0% found this document useful (0 votes)
26 views2 pages

JavaScript Object Notation & Classes Guide

The document explains Object Literal Notation in JavaScript, demonstrating how to create and access properties using dot and bracket notation. It also covers the use of classes, including the creation of static methods and inheritance, showcasing how to extend a class with a subclass. Examples illustrate the differences between object creation before and after ES6 syntax, as well as how to access object values and utilize class methods.

Uploaded by

sinhass110
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

JavaScript Object Notation & Classes Guide

The document explains Object Literal Notation in JavaScript, demonstrating how to create and access properties using dot and bracket notation. It also covers the use of classes, including the creation of static methods and inheritance, showcasing how to extend a class with a subclass. Examples illustrate the differences between object creation before and after ES6 syntax, as well as how to access object values and utilize class methods.

Uploaded by

sinhass110
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

**********************Object Literal Notation*************************

let firstObject = {};


[Link]('firstObject',firstObject);

let secondObject = {id : 177, name : 'Jane', age : 25};


[Link]('secondObject',secondObject);

The properties present inside the literal object can be accessed by using either a
dot notation or a bracket notation.

[Link]('Dot Notation',[Link]);
[Link]('Bracket Notation',secondObject.['name']);

[Link] = 188;
[Link]('New Id',[Link]);

//Before ES6
let name = 'john';
let age = 42;
let empObj = {
empname : name;
empage : age
}
[Link]('EmpObj',empObj);

//With ES6
let empObjes6 = {
name,
age
}
[Link]('newES6style',empObjes6);

To access the values present in literal object, use the [Link]() method.
[Link]('Values of secondObject',[Link](secondObject));

**********************Class & Static Keyword*************************


class Employee {
constructor(empId,empName,empAge){
[Link] = empId;
[Link] = empName;
[Link] = empAge;
}

swipeIn(){
[Link]('Employee Id',[Link],' has swiped in at '), new
Date().toLocaleDateString());

static code(){
[Link]('Employee is coding');
}
}
}

let empObj = new Employee(100,"Mark",23);


[Link]('Id ', [Link]);
[Link]('Name ', empObj['id']);

JavaScript classes can also have static methods.


Static methods can be created using static keyword.
[Link]();

Create objects using the class keyword.


Declare methods and create properties in this class.
How to access these properties using dot operator or square brackets.

***************************Inheritance******************************
class PartTimeEmployee extends Employee {
constructor(empid,empname,contractPeriod){
super(empid,empname);
[Link]=contractPeriod;
}
swipeIn(){
[Link](' Contract Employee Swiped In');
[Link]();
}
}

let empChild = new PartTimeEmployee(787,"Jane",3);


[Link]();
[Link]();
[Link]();

You might also like