Javascript Primitive Types !

Javascript Primitive Types !

The Easy Way >>>>>>

What are Primitive types ?

We often say that variables have or contain values. But just what is it that which they contain? To answer this seemingly simple question, we must look again at the data types structure in JavaScript. The types can be divided into two groups: Primitive types and Reference types. In this article we'd be discussing primitive types exclusively.

Primitive Types : The in-memory value of a primitive type is it's actual value (e.g. boolean: true | false , number: 122,33,45, 27, string: "Hello world", etc ). A primitive type can be stored in the fixed amount of memory available.

  • Strings
  • Numbers
  • Booleans
  • Null
  • undefined
  • Symbol

Primitive types are also known as: Scalar types or Simple types. The distinction between primitive and reference types is an important one, as they behave differently. Consider the following code that uses numbers (a primitive type):

var a = 5.39 ;  // Declare and initialize a variable
var b = a ;     // Copy the variable's value to a new variable
a = 3 ;          // Modify the value of the original variable
alert(b);       // Displays 5.39 ; the copy has not changed

This is the case of a Javascript Primitive Data Types because they are stored directly in the location the variable accesses, i.e they are stored on stack.