Si usas id
como selector entonces debes usar el caracter #
var uname = document.querySelector('#username').value;
var ulastname = document.querySelector('#userlastname').value;
var uage = document.querySelector('#userage').value;
var button = document.getElementById('sender');
var user = {
name: uname ,
lastname: ulastname,
age:uage
}
function printNameAge(person)
{
var {name, lastname ,age} = person;
console.log('Hello, My name is: ' + name + '.' + '\n' + 'I am: ' + age + ' years old.');
document.getElementById('data_pr').innerHTML = 'Hello, My name is: ' + name+ ' ' + lastname + '.' + '\n' + 'I am: ' + age + ' years old.';
}
button.addEventListener('click', ec =>
{
printNameAge(user);
});
<label for="username">User name: </label><input type="text" name="username" id="username">
<label for="userlastname">Last name: </label><input type="text" name="userlastname" id="userlastname">
<label for="userage">Age: </label><input type="number" name="userage" id="userage">
<input id="sender" type="submit" value="send_info">