Weird Parts __full__ | Javascript
If you’ve spent more than 48 hours with JavaScript, you’ve probably uttered the phrase: “Wait… why did it do that?”
JavaScript inserts a semicolon after return . It becomes return; and the object is never reached. javascript weird parts
function show() { console.log(this); } show(); // window (or global in Node) new show(); // {} (the new instance) If you’ve spent more than 48 hours with
Arrow functions don't have their own this —they inherit from the parent scope. That’s often a lifesaver, but it’s another thing to memorize. Every value in JS is inherently truthy or falsy. There are exactly 8 falsy values : That’s often a lifesaver, but it’s another thing
Put { on the same line as return . 6. this – The Shape-Shifter In most languages, this is predictable. In JavaScript, it depends on how you call the function.