#fundamentals
20 articles tagged with fundamentals
typeof vs instanceof - two ways to check a type in JS
JavaScript has two core operators for checking what type a value is, and each answers a different question. typeof returns one of 8 strings and has known gotchas (null, arrays). instanceof walks the prototype chain and fails for objects from an embedded <iframe>. A note on when to use which, and why arrays have a dedicated Array.isArray.
Property descriptors and getters/setters in JavaScript
Every object property in JS carries 4 flags under the hood (writable, enumerable, configurable, plus value or get/set). You rarely think about them - until something odd happens: an assignment doesn't change the value, delete doesn't remove the field, for...in skips the property. A note on what property descriptors are, how getters/setters work, and why Object.defineProperty has different defaults than an object literal.