JavaScript Primitive Data Types

 JavaScript Primitive Data Types


Why JS Loosely typed and Dynamic language?

In JavaScript variable not directly associated with any value type and can be assigned and re assigned values of all types. 

example

        let item = 2;
        item= 'bag';
        item = true;

Primitive Data Types

"A Primitive is data that is not object and has no methods."

  • string
  • number
  • bigint
  • boolean
  • undefined
  • symbol
  • null

All primitives are immutable(can be replace but cannot directly alter)

variable can be re assign to new value but existing value can not change in the way objects, arrays and functions altered .

example

//string methods doesn't mutate string

var name = "JHON"
console.log(name) // JHON
name.toLowerCase();
console.log(name) // JHON

 

//array methods mutate the array

var myArray = []
console.log(myArray); // []
myArray.push("car")
console.log(myArray); // ["car"]

 

//asignment assign primitive a new value but not a mutated value

name = name.toLowerCase(); // jhon


References

Comments

Popular posts from this blog

cannot find java exe neither null jre bin java exe nor null bin java exe exists(iReport)

Google Drive API (oauth 2.0) Upload Files Java

CSRF - Double Submit Cookie