Heterogeneous Arrays


#1



I am not sure why this error occurs. The comment lined is what I tried originally.


SyntaxError: Unexpected token


var color = {
    value = "blue",
    tint = "strong";
};
var bool1 = true;

// var myArray = [90, true, "Mike", color]

var myArray = [92, bool1, "Mike", color]


#2

This line

tint = "strong";

remove the ; and put , then inside the object color

var color = {
    value = "blue",
    tint = "strong";
};

change all the = with :


#3

Hi, there. No luck.

var color = {
value: "blue",
tint: "strong";
};

//var bool1 = true;

var myArray = [90, true, "Mike", color]

//var myArray = [90, bool1, "Mike", color]


#4

Here

var color = {
    value: "blue",
    tint: "strong"; <-- change the ; with ,
};

change the ; with ,

,


#5

Okay, I see what you mean.
I am looking at some documentation, and some developers do not even put a punctuation after it.
For instance, they have:
var color = {
value: "blue",
tint: "strong" <-- no ending
};

It seems to take either way. And, I was getting confused with the literal and object constructor syntax :confused:


#6

yes you could leave it without but since I see that you put the ; I thought that you want to put it .. but yes you could leave the last one without it


#7

Hi Wizmarco, is there any reason to put or not put the comma at the end of the object array? Or is it just a preference? I have found stories online that some instances where JavaScript will have problems if the { is not inline for if/then/else conditions. I haven't seen anything about the comma at the end of the object array - although visually for me it looks "wrong" in that I'm expecting another object. So, personally I would prefer not to see the comma there. Just wondering.


#8

Hi by

is there any reason to put or not put the comma at the end of the object array?

Do you mean to put a comma at the last propiety/value ?

var Object = {
   propriety1: value1,
   propriety2: value2,
};

If So...yes it's a preference


#9

Yes, that was the question. cheers!


#10

hey, I've a question, only boolean should be created in a diff var and be edited seperately? why it can be added just as true/false as the others except objects ofc. thank you!