We'll examine what a Javascript object is and how it functions. An object is a concept in programming languages that allows for data to be stored and manipulated by a program. Objects are more complex than variables, as they can have methods and properties. In addition to explaining what an object is, we'll also discuss how to create and use one in your programs.
A Javascript object is nothing more than a container for data. Objects have five basic characteristics that define them: name, attributes, methods, properties, and events:
When creating an object in a program, there are certain rules to follow. Each Javascript object has at least two methods, accessors and getters, and at most two properties:
You can also add properties to an already existing object; this is called inheritance and is used when creating objects from classes.
Properties are accessed by using a colon followed by a name followed by the property's name, for example: date: date-2017-09-06.
The first two parts of that line access the date attribute with its name; this is done with the first part ':'. The last part of that line retrieves the value of that attribute with its name ';' this is done with the last part '.'.
An object is a complex data structure used in many programming languages. It's a way for programs to store and access data without needing to use variables directly related to that data.
When creating an object in your programs, follow these guidelines:
We will talk about objects in javascript, a type of entity that can represent any physical or fictitious object, formed by a series of properties such as a key and a value.
We will create an object called "home". Objects in javascript will be represented in curly braces:
var home = {
rooms: 3,
kitchen: 1
}
home;
There are two ways to create objects:
function createEmployee(name, speed, strength){
var obj = new Object();
obj.name = name;
obj.speed = speed;
obj.strength = strength;
obj.sal = function(){
console.log(this.name);
};
return obj;
}
var man1 = createEmployee('John', 5, 10);
function Employee(name, speed, strength){
this.name = name;
this.speed = speed;
this.strength = strength;
this.say = function() {
alert(this.name);
}
}
var emp1 = new Employee('John', 10, 3);
Tips on SEO and Online Business
Next Articles
Previous Articles