JAVASCRIPT OBJECTS

DEFINITION OF OBJECT

DEFINITION OF OBJECT In JavaScript, objects are important. If you understand objects, you understand JavaScript. In this language, 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 Math is an object Regular expressions are always objects Arrays are always objects Functions are always objects Objects are always objects All JavaScript values, except primitive values, are objects. PRIMITIVE VALUES A primitive value is a value that has no properties [...]

By |2024-11-11T18:28:51+00:00April 2, 2022|0 Comments

OOP AND PROTOTYPE IN JAVASCRIPT

OOP AND PROTOTYPE IN JAVASCRIPT Object-oriented programming Is a paradigm that focuses on objects instead of functions. Let's look at the image below. WHAT ARE THE OBJECTS? Objects are data structures that integrate variables and functions within them. Variables are called properties and functions are called methods. The four pillars of OOP are shown in the image opposite. ENCAPSULATION To encapsulate means to enclose in a capsule. Related data and functions are grouped together. The functions or methods work internally with the data to perform the required operations. [...]

By |2024-11-11T18:29:53+00:00November 20, 2022|0 Comments

PROPERTY OF JAVASCRIPT OBJECTS

PROPERTY OF THE OBJECTS Properties are the most important part of any JavaScript object. An object is a collection of unsorted properties. Properties can usually be edited, added, and deleted, but some are read-only. The syntax for accessing the property of an object is: objectName.property      // person.age or: objectName["property"]   // person["age"] or: objectName[expression]   // x = "age"; person[x] The expression must return a property name. const person = {   firstName: "John",   lastName: "Doe",   age: 50,   eyeColor: "blue" }; person.firstname + " is " + person.age + " years old."; person["firstname"] + " is " + person["age"] + " years old."; FOR IN LOOP The JavaScript for ... in statement iterates through the properties of an [...]

By |2024-11-11T18:31:10+00:00April 3, 2022|0 Comments

METHODS OF JAVASCRIPT OBJECTS

METHODS OF OBJECTS fullName is an example of "javascript object methods". const person = {   firstName: "John",   lastName: "Doe",   id: 5566,   fullName: function() {     return this.firstName + " " + this.lastName;   } }; As for the keyword this, refer to this post (the keyword this). JavaScript methods are actions that can be performed on objects. A JavaScript method is a property that contains a function definition. Methods are functions stored as properties of the object. ACCESS THE METHODS An object method is accessed with the following syntax: objectName.methodName() You usually describe fullName () as a method of the person object and fullName as a property. The [...]

By |2024-11-11T18:31:59+00:00April 4, 2022|0 Comments

ACCESS TO JAVASCRIPT OBJECTS

ACCESS TO JAVASCRIPT OBJECTS ECMAScript 5 (ES5 2009) introduced Getter and Setter. They allow you to define access objects (calculated properties). THE KEYWORD GET This example uses a lang property to get the value of the language property. // Create an object: const person = {   firstName: "John",   lastName: "Doe",   language: "en",   get lang() {     return this.language;   } }; // Display data from the object using a getter: document.getElementById("demo").innerHTML = person.lang; THE KEYWORD SET This example uses a lang property to set the value of the language property. const person = {   firstName: "John",   lastName: "Doe",   language: "",   set lang(lang) {     this.language = [...]

By |2024-11-11T18:32:52+00:00April 5, 2022|0 Comments
Go to Top