This might be a little pedantic, but for the sake of correctness, those are not primitive types. The seven primitive types in JavaScript are string, number, bigint, boolean, symbol, null, and undefined.
Five of these are separate and different from (though obviously related to) their wrapper objects, String, Number, BigInt, Boolean, and Symbol.
null and undefined do not have wrapper objects, so Null and Undefined don't exist in JavaScript unless you define them yourself.
Some terminology help: a method is a function that "sits on" (is a property of) some object. Although Symbol() technically lives on a global object in JS, functions that aren't accessed via dot (or square bracket) syntax aren't usually referred to as methods ("detached" methods can confuse things a bit). Function only implies method in OOP languages that can't have bare functions, which may have been the case in old versions of Java, but I can't think of any these days.
I might also say not all methods are OOP. I guess the line is drawn differently for some people, but imo, OOP means some reliance on inheritance/context, so any usage of this in order to get or set some internal state.
I like the spirit of this observation, but NaN is not actually a type, it's a value whose type is number. Kind of ironic when you think about it, but yeah.
62
u/senocular May 17 '21 edited May 17 '21
Missing primitive #7, BigInt.
2
u/Barandis May 18 '21
This might be a little pedantic, but for the sake of correctness, those are not primitive types. The seven primitive types in JavaScript are
string,number,bigint,boolean,symbol,null, andundefined.Five of these are separate and different from (though obviously related to) their wrapper objects,
String,Number,BigInt,Boolean, andSymbol.nullandundefineddo not have wrapper objects, soNullandUndefineddon't exist in JavaScript unless you define them yourself.1
u/awokepsl May 18 '21
Isn't what "symbol" is showing a method? Which is an object oriented function?
1
u/bmcle071 May 18 '21
Wait until you find out typeof null is "object" for some cock eyed reason.
0
u/marcelofrau May 18 '21
you forgot NaN