A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Object Props

Object Properties

Object Props

  • In ES6 objects are a easy way to define custom data types.

  • An object is an instance which contains a set of key value pairs.

  • In ES6 objects can be initialized using new Object(), Object.create(),or using the literal notation.

Syntax to define object in ES6:-




let test =  {};  // object literal
let test2 = new Object(); //object  with new keyword 


 

Program To print values of variables :-





let object1 = {a: 'Aman', b: 'Heera' , c: 60 , d: {}};

console.log(object1.a);
console.log(object1.c); 

Output:-
Aman
60


 

Program 2 To print values of variables :-





let a = 'Aman';
let b = 'Heera';
let c =  60;
let d = {};
let object2 = {a: a, b: b, c: c, d: d};

console.log(object2.b);
console.log(object2.d);

Output:-
Heera
{}


 

Program 3 To print values of variables :-





let dog = 'Puppy';
let Name = 'Aman';

let someObject = 
{
 dog,
 Name
}
console.log(someObject);

Output:-
{dog: "Puppy", Name: "Aman"}


 

Program 4 To print values of variables with new keyword:-





let Data = new Object(); 
Data.Name = "Aman"; //define an object 
Data.Address = "Ambala"; 
Data.year = 1987;  

console.log(Data["Name"]) //access the object property 
console.log(Data["Address"]) 
console.log(Data["year"])

Output:-
Aman
Ambala
1987


 

LEARN TUTORIALS

.

.