JavaScript inserts a semicolon after return . It becomes return; and the object is never reached.
These quirks are frustrating until you understand why they exist. Once you do, you stop fighting the language and start leveraging it. javascript weird parts
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 : JavaScript inserts a semicolon after return
false , 0 , -0 , 0n (BigInt zero), "" , null , undefined , NaN . Once you do, you stop fighting the language
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.