I am not able to understand exactly what is difference between primitive and non primitive data types in JavaScript even it is declared using same name i.e var.
相关问题
- Is there a limit to how many levels you can nest i
- how to define constructor for Python's new Nam
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
Primitive Data types in ES6 are: Boolean Null Undefined Number String Symbol
The other data type which is not a primitive one is Object
Primitive data types are immutable values.
Javascript has five primitive data types: 1. number 2. string 3. boolean 4. undefined 5. null
Anything that doesn’t belong to any of these five primitive types is considered an object.
First 3 data types has a corresponding object constructor. For example
And then as an object:
For object constructor notice the
new
keyword. It creates object reference.Another thing to notice that
As for var keyword being same for all the cases,remember that Javascript is dynamically typed language. That means it resolves data type checking during runtime rather than compile time(like Java, C++ ).
This makes javascript extremely powerful. Though this unique feature has drawback too. Please co through this wikipedia for details: https://en.wikipedia.org/wiki/Type_system#Static_and_dynamic_type_checking_in_practice
Hope this helps.
Click here for details: