I routinely take the JavaScript primitives for granted. Sure, when I sit there and think about it I can come up with most of them and describe their properties. In more detail and for faster reference in the future, here are the JavaScript Primitives as I know them. More details and fun facts can be found at the Global Objects page of the mozilla developer documentation site.
- String - The String object is a constructor for strings, or a sequence of characters: var test = “a new string’. If you want all the characters available to you you could use the constructor: var test = new String(‘a new string’)
- Number - The Number object is a wrapper object allowing one to work with numerical values. A number object is created with the Number() constructor: var test = new Number(11) or var test = 11
- Boolean - The Boolean object is a wrapper for a boolean value. var test = true. I haven’t used it but you can instantiate them with a Constructor function to get the Boolean object and its methods.
- Object - The Object Constructor creates an object wrapper. I have never used the constructor mentor, I just shortcut it with var test = {}
- Array - The Array primitive is a type for arrays, a high level list like object
- NAN - The NAN is a global property ( much less yummy than it’s distant cousin naan) that is a value representing Not-A-Number
- Undefined - undefined is a global property representing the value undefined
- RegExp - The RegExp is an object that can be used for matching patterns in text. I have used both literal and Constructor patterns to instantiate them but prefer the literal method for succinctness.
In the really real world, there are quite a few more ‘Primitive’ types in JavaScript. But these are my best friends in daily work when it targeted at the web browser.