Saturday 28 May 2022

Objects in JavaScript.

 JavaScript is an Object-Oriented Language, Object is the most important Role in JavaScript.

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.

Object values are written as name: value pairs (name and value separated by a colon).

Example of JavaScript Object:

let User= {

  name : "username",

  age     : 25,

admin  :  false,

email:test@gmail.com

};

Object in 2 main things, one is key and the second is value.

in the above example, name, age, admin, and email are keys & username, 25, and test@gmail.com, false are valued.

Access object value:

we can access the value of the Object By key, If I need to Access the name of the user from the User object so, I can do,

var name = User.name or var name =User['name']

var name value is a username

        

Regards By Funkeylook.