Reasons to hate JavaScript #1098708976 let x = "a string" (x instanceof String) // returns false Because x isn't a String object yet. It's a literal. It only gets upgraded to an object when and if you call an object method/property on it, like x.trim() or x.length
-
-
Yeah, "upgrade" is probably not the best word. I meant: when you use a . operator on a literal, the literal is coerced to an object to find the method/prop. It isn't persistent / doesn't affect output. (PS works for numbers, too, but only if . it isn't parsed as a decimal!)pic.twitter.com/owgxEPaa5x
-
("literal" is probably also not the correct word, since the behavior applies to stored variables. "basic data type" vs object.)
- 2 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.