Objects and its internal representation in Javascript
Nov 5, 2020
In JavaScript, almost “everything” is an object.
- Booleans can be objects (if defined with the
new
keyword) - Numbers can be objects (if defined with the
new
keyword) - Strings can be objects (if defined with the
new
keyword) - Dates are always objects
- Maths are always objects
- Regular expressions are always objects
- Arrays are always objects
- Functions are always objects
- Objects are always objects
All JavaScript values, except primitives, are objects.
Objects are variables too. But objects can contain many values.
Using an Object Literal
var person = {firstName:”Happy”, lastName:”Potter”, age:48};
Using the JavaScript Keyword new
var person = new Object();
person.firstName = “Franklin”;
person.lastName = “Bean”;
person.age = 32;
JavaScript Objects are Mutable
Objects are mutable: They are addressed by reference, not by value.