I am new to javascript language. The format is given on web, I tried but it giving the undefined result.
var name = {
a : 'a',
b:'b',c:'c'
};
console.log(name.a);// undefined
console.log(name);// '[object object]'
The output is undefined ? why
You have a conflict with window.name. If you use name in a global context, the value is stringified. The solution is to use the variable only within a function context instead, or anywhere outside of global scope:
var f = function(){
var name = {
a : "a",
b : "b",
c : "c"
};
console.log(name.a);
console.log(name);
}
f();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With