While assigning values in javascript I came across this
var obj = {
resultCodeId: data[i].resultCodes[j].resultCodeId
};
var resultCodeId= data[i].resultCodes[j].resultCodeId;
How do ':' and '=' fundamentally differ in javascript ?Can variable also have properties or just objects in javascript have properties?
=
is for object property or global/local variable assignment. :
is only for property assignment at object definition.
Also: You can delete
a property. You cannot delete
a variable.
var obj = {
p1: 'im p1',
p2: 2
};
obj.p1 = 'im updated p1'; // assign a new value to object property
var v = 'just a var'; // is global outside a function and local inside a function
delete obj.p1; // is ok
delete v; // is not ok
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments