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 stringvar 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
Comments
Post a Comment