+ 1
why var name object return undefined?
var name = { user = "username", age = 22 }; var x = name.user; document.write(x); return undefined
1 Respuesta
+ 2
Because "name" is a JavaScript Reserved Words, and use a colon (:) instead of the (=) between the user (variables) and "usernames (values) same goes for age
Test this out:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Display the result here.</p>
<script>
var person = {
user: "usernames",
age: 22
};
document.getElementById("demo").innerHTML = person.user;
</script>
</body>
</html>
// output: usernames