100% found this document useful (1 vote)
2K views

ECMAScript6 Handson

This document covers various ECMAScript 6 features including: 1) Block scoping with let, functions to find the maximum of two numbers and sum of multiple numbers. 2) Destructuring arrays to assign variables. 3) Arrow functions to greet with a name. 4) Template literals to output a string with variables. 5) Classes to define and use a Car class. 6) Symbols to define private properties for an Employee object.

Uploaded by

Rutuja Borhade
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)
2K views

ECMAScript6 Handson

This document covers various ECMAScript 6 features including: 1) Block scoping with let, functions to find the maximum of two numbers and sum of multiple numbers. 2) Destructuring arrays to assign variables. 3) Arrow functions to greet with a name. 4) Template literals to output a string with variables. 5) Classes to define and use a Car class. 6) Symbols to define private properties for an Employee object.

Uploaded by

Rutuja Borhade
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 100000785578037 from CourseHero.com on 09-06-2021 13:07:50 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 100000785578037 from CourseHero.com on 09-06-2021 13:07:50 GMT -05:00

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy