What is the difference between declaring a JSON object with: y =?

6

I've always had doubts about the difference between obj1 and obj2

var obj1 = {
  propiedad1: String,
  propiedad2: Boolean,
  propiedad3: Number,
  propiedad4: null,
  propiedad5: "Opcion1" || "Opcion2",
  propiedad6: {
     propiedad1: String,
     propiedad2: Boolean,
  }
}
var obj2 : {
  propiedad1: String,
  propiedad2: Boolean,
  propiedad3: Number,
  propiedad4: null,
  propiedad5: "Opcion1" | "Opcion2",
  propiedad6: {
     propiedad1: String,
     propiedad2: Boolean,
  }
}

When is the : used and when the = ?

    
asked by Daniel Enrique Rodriguez Caste 23.10.2017 в 18:31
source

1 answer

7

The operator = is for assignment in the language while : is for definition in the notation . Let me explain:

Javascript is a programming language and

  

When you create an object in the programming code, the values can change at any time during execution. To do so, you simply create variables and assign them values by using = . Example: var x = 2;

On the other hand, JSON is just one notation for information exchange between different languages and platforms and

  

When you create an object in Json notation, the values no will change once assigned, so you are defining . This is only valid in a JSON string since this is defined .

    
answered by 23.10.2017 / 18:46
source