Value and reference types

后端 未结 3 1998
礼貌的吻别
礼貌的吻别 2021-02-04 02:46

I know that there are 6 data types in JavaScript.

What are the \"reference\" types in JavaScript and what are the \"value\" data types in JavaScript?. Could someone list

相关标签:
3条回答
  • 2021-02-04 03:12

    From the standard#sec-8

    The ECMAScript language types are Undefined, Null, Boolean, String, Number, and Object

    The only "reference" type is the Object.

    0 讨论(0)
  • 2021-02-04 03:23

    undefined, null, number, string, boolean and object

    object is a reference type.

    0 讨论(0)
  • 2021-02-04 03:26

    undefined, null, number, string, boolean and object of which only object is a "reference" type.

    There is no assignment by reference or pass by reference in javascript, whenever you pass/assign a "reference" type, you pass/assign a copy of the reference, you don't create a reference of the reference which would have different implications.

    You can use these functions:

    function isReferenceType( value ) {
         return Object(value) === value;
    }
    
    function isPrimitiveType( value ) {
         return Object(value) !== value;
    }
    
    0 讨论(0)
提交回复
热议问题