Unexpected error need immediate help


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-9Sgpi/3/3?curriculum_id=506324b3a7dffd00020bf661#


for some reason it says 'Syntax error unexpected token var'

here is the code

var myObject = {
  name: 'Eduardo',
  type: 'Most excellent',
  interests: var array=[3,true];
  
};


#2

So you want to assign an array to the interests property, right? You overcomplicated this a bit. You just need to follow the syntax of the previous properties:

interests: [3, true]

#3

Thank you very much for the help! Can you tell me why "var array=" needed to be ommited from "var array=[3,true]"?


#4

You're very welcome :slight_smile:

Well, we use var keyword to create global and local variables. Here we want to assign a value to the property - it will be assigned to the specific object (myObject) not to the scope.

Basically, if you want to create an object (of any type) use var, if you want to add some information to the object - do not use var.


#5

OK :slight_smile: Thanks again. I would've been stuck there for a long time had you not helped me!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.