Difference between primitive and non-primitive data types in JavaScript

I can’t understand exactly what the difference between primitive and non-primitive data types is in JavaScript, even if it is declared using the same name ie var.

+6
source share
5 answers
Data Types (JavaScript):

Primary Data Types
The primary (primitive) data types are:
String, Number, Boolean

Composite Data Types
The composite (reference) data types are:
Object, Array

Special Data Types
The special data types are:
Null, Undefined

Click here for details:

  var test1 = 1;
  var test2 = "Something";
  var test3 = true;
  var test4 = {};
  var test5 = new Array();
  var test6 = new Date();
  var test7;
  var test8 = null;

  alert(typeof (test1)); //number
  alert(typeof (test2)); //string
  alert(typeof (test3)); //boolean
  alert(typeof (test4)); //object
  alert(typeof (test5)); //object
  alert(typeof (test6)); //object
  alert(typeof (test7)); //undefined
  alert(typeof (test8)); //object
+3
source

Javascript has five primitive data types: 1. number 2. line 3. boolean 4. undefined 5. null

Everything that does not belong to any of these five primitive types is considered an object.

The first 3 data types have a corresponding object constructor. for example

var word = "something";

And then as an object:

 var word = new String("something");

new. .

,

var greeting = "something";
var word = new String("something");
greeting == word ----> True as their value is same
greeting === word -----> False because there value same but type is different .

var , , Javascript . , , (, Java, ++).

javascript . . , : https://en.wikipedia.org/wiki/Type_system#Static_and_dynamic_type_checking_in_practice

, .

+3

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures

ES6: Null Undefined Number String Symbol

, , Object

.

+1

: 1. 2. 3. 4. 5.

: 1.Object 2.Array 3.RegExp

+1

- , . : , , , , . .

Derived data types are types that are derived from an existing primitive data type connected together, for example: an array, an object, etc. A derived data type simply gets a reference to the memory allocation where the values ​​are stored.

0
source

Source: https://habr.com/ru/post/1612686/


All Articles