[go: up one dir, main page]

100% found this document useful (1 vote)
162 views2 pages

ECMAScript6 Handson

This document contains examples of various ECMAScript 6 features including: 1) Block scoping with let, functions with parameters, arrow functions, and exporting objects. 2) Destructuring arrays and objects. 3) Template literals for string interpolation. 4) Defining a class with constructor, properties, and methods. 5) Using symbols as object keys for private properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
162 views2 pages

ECMAScript6 Handson

This document contains examples of various ECMAScript 6 features including: 1) Block scoping with let, functions with parameters, arrow functions, and exporting objects. 2) Destructuring arrays and objects. 3) Template literals for string interpolation. 4) Defining a class with constructor, properties, and methods. 5) Using symbols as object keys for private properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ECMAScript 6

#######Block of Variables:#######

let maximum = (a,b) => {


var max;
if (a>b)
max = a;
else
max = b;
return max
}
module.exports = {maximum}

#######Block of Variables:#######

#######Parameters :#######

const sum = (...args) => {


var result = 0;
args.forEach(function(args){ result += args;})
return result;

m
}

er as
module.exports = {sum}

co
eH w
#######Parameters :#######

o.
#######Destructuring Content######rs e
ou urc
const states = [['Tamilnadu'], ['Punjab', 'Haryana']]

var [Chennai, Chandigarh] = [states[0], states[1]]


o

module.exports = {states}
aC s
v i y re

#######Destructuring Content######

#######Arrow Function##############
Write an arrow function which takes your name as input and prints "Hello
your_name" to console.
ed d
ar stu

const greet = (your_name) => {


return ('Hello ' +your_name)
}
module.exports = {greet}
sh is

#######Arrow Function##############
Th

#######Template Literals###########

let a = 1; let b = 2;
Achieve the following output using template literals.
"The sum of 1 and 2 is 3"

const sum = (a,b) => {


var c = a+b;
return (`The sum of ${a} and ${b} is ${c}`)
}
module.exports = {sum}

#######Template Literals###########

#############Class#################

This study source was downloaded by 100000832806195 from CourseHero.com on 10-07-2021 22:51:38 GMT -05:00

https://www.coursehero.com/file/75470599/ECMAScript6-handsontxt/
class Car{

constructor(name, distance){
this.name = name;
this.distance = distance;
}

carDistance() {
return (this.name +' had travelled for ' +this.distance+' miles')
}

}
let Car1 = new Car('Audi', 100);
const msg = Car1.carDistance();

module.exports = {msg}

#############Class#################

############Symbols################

m
er as
Create an object Employee with properties:

co
--name as "rajesh" --phone as 9800000000, --symbol "email" as

eH w
"rajesh@gmail.com".
After creating the object, display:

o.
--All the keys of object "employee" --Only private keys (symbols) --Only public
rs e
keys (non sumbol)
ou urc
let email = Symbol();
let Employee = {
name:"rajesh",
o

phone:9800000000,
aC s

[email] : "rajesh@gmail.com"
v i y re

};

let allKeys = Reflect.ownKeys(Employee);


let privateKeys = Object.getOwnPropertySymbols(Employee);
let publicKeys = Object.keys(Employee);
ed d
ar stu

module.exports = {Employee, allKeys, privateKeys, publicKeys}

############Symbols################
sh is
Th

This study source was downloaded by 100000832806195 from CourseHero.com on 10-07-2021 22:51:38 GMT -05:00

https://www.coursehero.com/file/75470599/ECMAScript6-handsontxt/
Powered by TCPDF (www.tcpdf.org)

You might also like