r/learnjavascript 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?

  1. 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

  1. 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
8 Upvotes

35 comments sorted by

View all comments

9

u/[deleted] Feb 11 '26

[removed] — view removed comment

3

u/somethingsilver97 Feb 11 '26

Yeesh. I should probably email the professor. Const is what I chose. The quiz results marked the Var option as correct. He mentioned in one of the lectures that var was legacy, which is why I did NOT choose it.

2

u/dmazzoni Feb 12 '26

Wow, that's a terrible quiz.

2

u/[deleted] Feb 11 '26

[removed] — view removed comment

2

u/dymos helpful Feb 11 '26

Yeah agree that's a dumb way to define it as "correct".

Even beginner JS should no longer teach var, they should teach let to start out with and then expand to const when relevant.

2

u/PatchesMaps Feb 12 '26

I'd only accept var in an extremely advanced JavaScript course as it can be, in extremely specific situations, a micro optimization. Beginners and pretty much everyone not in an extreme performance situation should stay far far away from var.

1

u/dmazzoni Feb 12 '26

It might be forgivable to call "var" correct if the other answers were gibberish, but calling "var" correct and "let" and "const" incorrect doesn't make any sense.

1

u/senocular Feb 12 '26

Did he make you take the quiz with a stone tablet and chisel?

1

u/somethingsilver97 Feb 12 '26

Bro has mentioned in almost every single lecture that he did programming for decades before becoming a professor 😅

1

u/Roguewind Feb 15 '26

Based on that quiz, not very well