What is it for the ":" in a variable? [SOLVED]

What is it for the ":" in a variable? [SOLVED]
0.0 0

#1

Example:

var o = { x : 1}

That that’s means?


#2

It’s like the =, but for object properties. Here you have an object with a property named x, and that x has a value of 1.


#3

You’re defining an object called “o”, that contain key:value pairs.

In your example, you have one key called “x” with a value of 1.
such that:

o.x = 1   // here, you're asking what is the value of the key "x" in object "o" 

// you can also ask for the object what are it's keys
Object.keys(o);
// returns an array with one element ["x']

// you can also ask what are it's values
Object.values(o); 
// returns an array [1]

You can define multiple keys, like

var customer = {name: "john", lastname: "doe"}
customer.name  // returns "john"
customer.lastname // returns "doe"


#4

Thanks u so much for the explanation!


#5

Thank u so much for taking the time to answer!