[Cheat Sheet] Javascript – Data Types

Note: This is part of Javascript learning roadmap.

Data types

  • 7 defined data types
    • 6 primitives
    • Object (see [Cheat Sheet] Javascript – Objects – available soon)
  • all primitives (including string)  are immutable – their value cannot be changed
  • they are accessed by value – you manipulate the actual value stored in the variable


  • null
    • primitive type – represents absence of a value
    • evaluates to false in boolean expressions
    • evaluates to ‘0’ in numeric expressions
  • undefined
    • primitive type – represents an unknown value
    • returned when a non-existent object property is called
    • evaluates to false in boolean expressions
    • evaluates to NaN when used in numeric context (var a; a+2; //evaluates to NaN)
  • boolean
    • true and false
  • number
    • starts with ‘0’ – octal [0-7]  – to be avoided – error in strict mode 
    • starts with ‘0x ‘- hexadecimal [0-7] and [A-F]
    • starts with ‘0B’ or ‘0b’ – binary – [0,1]
    • Javascript doesn’t have a different primitive for non-integers like other mainstream languages (floats are also of type number)
  • string
    •  one of the important differences between JS and main stream languages is that strings are primitives, not objects
    • Javascript also provides an object wrapper String() which contains helper function
    • every function of the object wrapper can be used on the primitive as well
      • behind the scenes, JS automatically converts the string literal to a temporary String object -> calls the method -> discards the object (Object Wrapper article – coming soon)
  • symbol
    • new in ECMAScript 2015
    • instances are unique and immutable


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s