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 them by these 2 categories?
-
3Where did you hear of these categories existing?Some Guy– Some Guy2012年07月17日 11:10:21 +00:00Commented Jul 17, 2012 at 11:10
-
1from strongly typed languages.. like C#, Java..obenjiro– obenjiro2012年07月17日 11:54:33 +00:00Commented Jul 17, 2012 at 11:54
3 Answers 3
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;
}
Comments
From the standard#sec-8
The ECMAScript language types are Undefined, Null, Boolean, String, Number, and Object
The only "reference" type is the Object.