You are on page 1of 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