+ 3
Array question
This is a question from a timed JavaScript Challenge. What is the output? var e = []; e["Yes"] = 7; console.log(e["Yes"]); e[null] = 8; console.log(e[null]); e[true] = 3; console.log(e[true]); e[false] = 2; console.log(e[false]); The output is 7832. Is this an example of non-integer indices? Through Google I found this in Stack Overflow: " JS arrays do not have key indices, those JS objects are considered object literals. so: foo["bar"] = 1; foo.bar === foo["bar"]; //true foo["bar"] === foo[0]; //false This is one of the many subtle quirks about JS that throw people off easily. " Am I connecting the correct concept with this challenge question? Thank you in advance!
3 Respuestas
+ 4
Yes ~ and sorry for the late response
It creates an object that contains one property. That property has a key name of foo, and that key called foo contains a vaue of "bar"
If you assign the object to a variable, such as baz, you can retrieve the property value by using either array-index notation, or by accessing the appropriate property of that object.
+ 2
BroFarOps 🎃👻🍬 Could I pick your brain?
+ 2
That's so cool, thanks!