Last Updated: February 25, 2016
·
633
· phantom

Javascript primitive data type

  • Primitive types are:
    undefined
    null
    boolean
    number
    string

  • undefined : when a variable is declared using var but not initialized.

    var nonInitializedVariable;

  • null : Null is an empty object pointer
    var InitializedVariable = null;

  • boolean : boolean literals are true and false and thy are case sensitive.

    var validBool = true; /// variable is defined and initialized        
    var nonValidBool = True; /// Error var True is not defined        

Falsy values:
false, "" empty string, 0, NaN, null, undefined

This is important while initializing varable eg:

  var someMessage = "this is example";    
if( someMessage ){   /// expresion is converted to true   }
  • number : numbers using IEEE-754 format to represent both integers and floating-point values

    var myn = 9; /// integer

    var fl = 1.7; /// floating number

http://en.wikipedia.org/wiki/IEEE_floating_point

  • string - string data type represents a sequence of zero or more 16-bit unicode characters. Strings can be delineated by either double quotes (“) or single quotes (‘).

    var oneQuote = 'this is valid string';    
    var twoQuote = "this is also valid string";