January 2020
Intermediate to advanced
548 pages
13h 36m
English
The in operator will return true if a property can be found in an object:
'foo' in { foo: 123 }; // => true
The left-side operand will be coerced to its primitive representation, which, if not Symbol, will be coerced to String. Here, we can see how a left-side operand that is Array will be coerced into a comma-separated serialization of its contents (the native and default way that arrays are coerced to primitives, thanks to Array.prototype.toString):
const object = { 'Array,coerced,into,String': 123};['Array', 'coerced', 'into', 'String'] in object; // => true
All seemingly numeric property names in JavaScript are stored as strings, so accessing someArray[0] is equal to someArray["0"], and therefore enquiring as to ...
Read now
Unlock full access