memory, or CPU a container can use,
In modern engines, performance-wise, there’s no difference whether we take a property from an object or its prototype. They remember where the property was found and reuse it in the next request.
Object properties, besides a value, have three special attributes (so-called “flags”): writable – if true, the value can be changed, otherwise it’s read-only. enumerable – if true, then listed in loops, otherwise not listed. configurable – if true, the property can be deleted and these attributes can be modified, otherwise not.
Arrow functions: Do not have this Do not have arguments Can’t be called with new They also don’t have super, but we didn’t study it yet. We will on the chapter Class inheritance
the local variable x is known to the engine from the beginning of the function, // but "unitialized" (unusable) until let ("dead zone") // hence the error
As you may have read in the article Variable scope, a variable starts in the “uninitialized” state from the moment when the execution enters a code block (or a function). And it stays uninitalized until the corresponding let statement. In other words, a variable technically exists, but can’t be used before let.
he main area of application for WeakMap is an additional data storage.
WeakMap does not support iteration and methods keys(), values(), entries(), so there’s no way to get all keys or values from it. WeakMap has only the following methods:
WeakMap The first difference from Map is that WeakMap keys must be objects, not primitive values:
以大观小
alert( 1.35.toFixed(20) ); // 1.35000000000000008882
This example clearly shows that primitives are not objects.
but after that the “wrapper object” disappears, so in the last line str has no trace of the property.
For global symbols, not only Symbol.for(key) returns a symbol by name, but there’s a reverse call: Symbol.keyFor(sym), that does the reverse: returns a name by a global symbol.
n order to read (create if absent) a symbol from the registry, use Symbol.for(key).
In contrast, Object.assign copies both string and symbol properties
Object.keys(user) also ignores them. That’s a part of the general “hiding symbolic properties” principle. If another script or a library loops over our object, it won’t unexpectedly access a symbolic property.
The optional chaining ?. stops the evaluation and returns undefined if the part before ?. is undefined or null.
obj?.prop – returns obj.prop if obj exists, otherwise undefined. obj?.[prop] – returns obj[prop] if obj exists, otherwise undefined. obj?.method() – calls obj.method() if obj exists, otherwise returns undefined.
We can use ?. for safe reading and deleting, but not writing The optional chaining ?. has no use at the left side of an assignment: