Data types in JavaScript
Inspired from an exercise in Hackerrank.com, I found the opportunity to present you the data types that JavaScript defines, which are the following six:
- undefined
- null
- number
- string
- boolean
- object
Arrays and functions are plain objects in JavaScript and they both belong to the object data type. All data types except the object are called primitive or value types. Each variable of this category has its own copy of the assigned value and operating on one of many variables that contain the same value is not affecting the value that is referenced from the other variables. Here is an example pointing that out:
The object data type is a reference type which means that inside a variable a reference to the object is assigned. If two or more variables contain the same reference to an object, then when operating on one variable will change the object and since the other variable reference the same object, this will affect the referenced value for all variables. Here is an example:
You can find the code of the article here.