Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

 var states = [['Tamilnadu'], ['Punjab', 'Haryana']]

 Define Chennai and Chandigarh variables using Destructuring so that variables Chennai =
['Tamilnadu'], Chandigarh = ['Punjab', 'Haryana']
 Solution:

 const states = [['Tamilnadu'], ['Punjab', 'Haryana']];


 const [Chennai, Chandigarh] = states;
 module.exports = {states, Chennai, Chandigarh};
 Write an arrow function which takes your name as input and prints "Hello your_name" to
console.

 const greet = (name) => {



 this.name=name;
 return 'Hello '+ this.name;

 };
 module.exports = {greet}
 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) => {


 this.a = a;
 this.b = b;
 return "The sum of " + a + "and " + b + "b is " + (a+b);

 }
 module.exports = {sum}
 Create a class Car with a constructor function which accepts 2 parameters (name and distance).
Include a prototype method in class, which returns a message(msg) "car name(name) had
travelled for distance(distance) miles".

 class Car {
 constructor(name, distance)
 {
 this.name=name;
 this.distance=distance;
 }
 carDistance()
 {
 return this.name +'had travelled for ' + this.distance + '
miles';

This study source was downloaded by 100000844313934 from CourseHero.com on 03-28-2022 03:40:24 GMT -05:00

https://www.coursehero.com/file/68103783/hackerank-es6docx/
 }
 }
 let Car1 = new Car('Audi', 100);
 const msg = Car1.carDistance();
 console.log(msg);
 module.exports = {msg}

 Create an object Employee with properties:



 --name as "rajesh" --phone as 9800000000, --symbol "email" as "rajesh@gmail.com".

 After creating the object, display:

 --All the keys of object "employee" --Only private keys (symbols) --Only public keys (non sumbol)

 let email = Symbol();


 let Employee = {

 name : "rajesh",
 phone :9800000000,
 [email] : "rajesh@gmail.com"
 };

 let allKeys = Reflect.ownKeys(Employee);
 let privateKeys = Object.getOwnPropertySymbols(Employee);
 let publicKeys = Object.getOwnPropertyNames(Employee);

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

This study source was downloaded by 100000844313934 from CourseHero.com on 03-28-2022 03:40:24 GMT -05:00

https://www.coursehero.com/file/68103783/hackerank-es6docx/
Powered by TCPDF (www.tcpdf.org)

You might also like