In this case the string value is coerced to a string object in order to access the property length. If primitives have no properties, why does "this is a string".length return a value?īecause JavaScript will readily coerce between primitives and objects. Typeof new String("this is a string") //"object" These objects are instances of the Boolean, String and Number constructors respectively. The primitive types boolean, string and number can be wrapped by their object counterparts. In JavaScript there are 7 primitive types: undefined, null, boolean, string, number, bigint and symbol. String, number, boolean, null, undefined, and symbol. You may not know it but, in JavaScript, whenever we interact with string, number or boolean primitives we enter a hidden world of object shadows and coercion.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |