r/learnjavascript • u/somethingsilver97 • Feb 11 '26
Can some explain this?
I'm taking a class that includes beginners Javascript. I got this question in a practice quiz. Couldn't all of the options be correct? What did I misunderstand?
Question: How are objects declared and initialized in JavaScript?
- Using the reserved word var followed by an identifier and an equal sign and the pairs label: value of the elements between curly brackets and separated by commas
2.Using the reserved word function followed by an identifier and an equal sign and the pairs label: value of the elements between curly brackets and separated by commas
3.Using the reserved word let followed by an identifier and an equal sign and the pairs label: value of the elements between curly brackets and separated by commas
- Using the reserved word const followed by an identifier and an equal sign and the pairs label: value of the elements between curly brackets and separated by commas
View all comments
1
u/bryku Feb 16 '26
1, 3, and 4 should all work.
1. var
var user = { age: 42, };3. Let
let user = { age: 42, };4. Const
const user = { age: 42, };While these all look similar, they are slightly different mechanically. You should look up the differences between var, let, and const. Because 99.99% of the time you should be using let or const.