Unexpected error need immediate help



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];


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]


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


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.


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


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