Are booleans objects in JavaScript? Is it true that “everything is an object” in JavaScript?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Primitives are not objects, everything else (any standard object) is an object. However, most primitives (all apart from
undefinedandnull) have an object counterpart.So
is not an object, but
is.
Since two objects are only equal if they refer to one and the same object, using the object version of primitives should better be avoided:
Or especially with boolean objects, using them with any boolean operators will create unexpected results. An object reference always evaluates to
true, so the outcome of usingbwould be:There is no real advantage of using these object versions anyway, since JavaScript is autoboxing primitives when you try to call methods on them. That’s why calls like:
are possible.