Objects in JavaScript
Published by
sanya sanya
The objects in the javascript are something that has the properties and method. Let's take an example, everything we encounter in our day-to-day life is an object. For example, computers, mouse, and so on.
Such as in real life, In Javascript also everything is an object. Regular expressions, arrays, and functions, are always objects. However, Booleans, numbers, and strings can be objects.
All the values in the javascript except for the primitive data types values are objects.
Javascript Primitive Values
The Primitive Values are those values that have no properties and no methods. Moreover, Primitive Data Types are the data types that have primitive values.
There are seven Primitive values in Javascript mentioned below -
- String
- Number
- Boolean
- Null
- Undefined
- Symbol
- BigInt
One special thing about the primitive values is that these values are immutable and cannot be changed.
Creating an Object in Javascript
In javascript, we can define and create our objects. Several ways to create different Javascript Methods are as follows -
- By using an Object Literal, Create a single object. The code for the same is as follows -
- Using the
newkeyword, create a single object. - Using
Object.create()to create an object - First define an object constructor, and then create objects of the constructed types.
const person = {number: "one", name: "brock", age:50};
const obj = new Object(); obj.name = "Shivam"; obj.age = 25; obj.class = 10
Objects in Javascript are mutable. Hence, we can perform some operations such as adding new items, deleting, and so on.
Properties Attributes
Several Properties Attributes supported by Javascript Object are as follows -
- All the properties have values and names
- The given value must be one of the property's attributes.
- Other attributes rather than the mentioned one are - enumerable, configurable, and writable.
- All the attributes define how can be the property writable or readable.
- The `value attribute` can be changed but not all the others.
Library
WEB DEVELOPMENT
Basic
HTML - Hyper Text Markup Language
CSS - Cascading Style Sheets
JavaScript
An Introduction to Javascript!
How to Run JavaScript Code
Variables in Javascript
Numbers in JavaScript
JavaScript Operators
Data Types in JavaScript
Conditional Statements
Switch Statements
Loops in Javascript
Arrays in JavaScript
Strings in JavaScript
Objects in JavaScript
Object Methods in JavaScript
Functions in JavaScript
Object Referencing and Copying in JavaScript
' this' keyword
Asynchronous Programming in JavaScript
Callbacks in JavaScript
Promises in JavaScript
Constructor Functions in JavaScript
Async and Await in JavaScript
Type Conversion in Javascript
DOM
Currying in JavaScript
Network Request
Frontend
Backend
Interview Questions
FAANG QUESTIONS
On this page
Javascript Primitive Values
Creating an Object in Javascript
Properties Attributes

