hi @Lady i just got rage-baited by some very poor javascript criticism would you also like to be annoyed by it
@wallhackio @Lady she’s playing Leyendas Pokémon: Arceus but i will read it to her if you want
@wallhackio @Satsuma 🫵 zoomer
@Lady @Satsuma Here, have a transcription of the most appalling part of the video:
Author: "And why is nearly everything an object? Why is Strings objects? Why are numbers objects? They're just numbers. Like I get that it's for method but does NaN
need to be an object?"
[screen shows author using the node.js REPL calling the valueOf
method of NaN
]
Author: "Why would anyone want to get the value of something that explicitly states it isn't a number?"
[Cut to screenshot of freecodecamp.org's description of JavaScript which claims that "JavaScript is not a class-based object-oriented language".]
Author: "Any many argue that JavaScript isn't object-oriented."
[cut to screenshot of towardsdatascience.com's description of JavaScript which claims that "Nearly everything in JavaScript is an object".]
Author: "Looks pretty-object oriented to me... And why is that functions are also classes? That's what [ES6] classes are for."
@wallhackio @Satsuma honestly thinking everything is an object is imagining javascript to be simpler and more consistent than it actually is
@wallhackio @Satsuma no, strings, numbers, etc in javascript are explicitly not objects, they are literal (immutable) values
this is why `"foo" === String("foo")` but `"foo" !== new String("foo")`; the result of a new expression is always an object, whereas the result of `String("foo")` is a literal string value
cf. the `typeof` operator
the purpose of valueOf is to get the literal value of a wrapped object type, so `"foo" === (new String("foo")).valueOf()`
@wallhackio @Satsuma the confusion is that for all of these things Javascript is doing `new Object(…)` behind the scenes, so that
"foo".toString()
is literally
new Object("foo").toString.call("foo");
"foo" itself is not an object, javascript just does a lot of behind-the-scenes object wraps in necessary places to make it work like one in many cases
@wallhackio @Satsuma so what you are thinking of as “numbers and strings” is actually “object-wrapped numbers and strings” which do indeed have the internal slots that you describe
but what is in those internal slots? the original immutable number and string literals
@wallhackio @Satsuma you can't Object.setPrototypeOf("foo") and have it work, importantly
@Lady @Satsuma it is so cool that i had a fundamental misunderstanding of a language i loved that is really cool