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
6 Upvotes

35 comments sorted by

View all comments

Show parent comment

11

u/Lumethys Feb 12 '26

Technically a function is an object

9

u/dmazzoni Feb 12 '26

You're right, I should have been more precise. It sounds like what #2 is asking is this:

function foo = { "x": 2 }

which is not valid JavaScript, it's not a way to declare a function or an object.

Yes, if you declare a function using the correct syntax, then that function would also be an object.