Sololearn JavaScript course ECMAScript 6 answers
Here are all the questions and answers that I hope will help you learn JavaScript course.
Sololearn JavaScript course Overview answers
Sololearn JavaScript course Basic Concepts answers
Sololearn JavaScript course Conditionals and Loops answers
Sololearn JavaScript course Functions answers
Sololearn JavaScript course Objects answers
Sololearn JavaScript course Core Objects answers
Sololearn JavaScript course DOM & Events answers
55.1 Lesson
Intro to ES6
Question:
ECMAScript 6
JavaScript and ES6 are different technologies for different purposes.
Answer:
False
56.1 Lesson
ES6 Variables and Strings
Question:
var & let
What is the output of this code?
function letItBe() {
let v = 2;
if (true) {
let v = 4;
console.log(v);
}
console.log(v);
}
letItBe();
Answer:
4 2
Question:
const
Fill in the blanks to make a constant named total and the variable i that is only accessible inside the loop.
Answer:
const total = 100;
let sum = 0;
for(let i = 0; i < total; i++) {
sum += i;
}
Question:
Template Literals in ES6
Fill in the blanks to output "We are learning ES6!".
Answer:
let n = 6;
let s = 'ES';
let msg = `We are learning ${s + n}!`;
console.log(msg);
57.1 Lesson
Loops and Functions in ES6
Question:
Loops in ECMAScript 6
Fill in the blanks to iterate through all the characters using the for...of loop.
Answer:
for (let ch of "SoloLearn") {
console.log(ch);
}
Question:
Functions in ECMAScript 6
Fill in the blanks to declare an arrow function that takes an array and prints the odd elements.
Answer:
const printOdds = (arr) => {
arr.forEach(el => {
if (el % 2 != 0) console.log(el);
});
}
Question:
Default Parameters in ES6
What is the output of this code?
function magic(a, b = 40) {
return a + b;
}
console.log(magic(2));
Answer:
42
58.1 Lesson
ES6 Objects
Question:
ES6 Objects
Fill in the blanks to make this code run and print 60.
Answer:
let car = {
speed: 40,
accelerate() {
this.speed += 10;
}
};
car.accelerate();
car.accelerate();
console.log(car.speed);
Question:
Computed Property Names
Fill in the blanks to create an object with its properties.
Answer:
let prop = 'foo';
let o = {
[prop]: 'lol',
['b' + 'ar']: '123'
};
Question:
Object.assign() in ES6
What is the output of this code?
const obj1 = {
a: 0,
b: 2,
c: 4
};
const obj2 = Object.assign({c: 5, d: 6}, obj1);
console.log(obj2.c, obj2.d);
Answer:
46
59.1 Lesson
ES6 Destructuring
Question:
Array Destructuring in ES6
What is the output of the following code?
let names = ['John', 'Fred', 'Ann'];
let [Ann, Fred, John] = names;
console.log(John);
Answer:
Ann
Question:
Object Destructuring in ES6
What is the output of the following code?
const obj = {one: 1, two: 2};
let {one:first, two:second} = obj;
console.log(one);
Answer:
Error
60.1 Lesson
Rest & Spread
Question:
ES6 Rest Parameters
What is the output of the following code?
function magic(...nums) {
let sum = 0;
nums.filter(n => n % 2 == 0).map(el => sum+= el);
return sum;
}
console.log(magic(1, 2, 3, 4, 5, 6));
Answer:
12
Question:
The Spread Operator
What is the output of the following code?
let nums = [3, 4, 5];
let all = [1, 2, ...nums, 6];
console.log(all[3]);
Answer:
4
61.1 Lesson
ES6 Classes
Question:
Classes in ES6
Fill in the blanks to declare a class Point with a constructor initializing its x and y members.
Answer:
class Point {
constructor(a, b) {
this.x = a;
this.y = b;
}
getX() { return this.x; }
getY() { return this.y; }
}
Question:
Class Methods in ES6
Fill in the blanks to output "Rex barks."
Answer:
class Dog {
constructor(name) {
this.name = name;
}
bark() {
console.log(this.name + ' barks.');
}
}
let d = new Dog('Rex');
d.bark();
Question:
Inheritance in ES6
Fill in the blanks to declare a class Student which inherits from the Human class.
Answer:
class Human {
constructor(name) {
this.name = name;
}
}
class Student extends Human {
constructor(name, age) {
super(name);
this.age = age;
}
}
62.1 Lesson
ES6 Map & Set
Question:
ES6 Map
What is the output of this code?
Answer:
1
Question:
ES6 Set
Fill in the blanks to create and output a set with the values 1, 2, 3.
Answer:
const set = new Set();
set.add(1).add(2).add(3);
for(let v of set.values())
console.log(v);
63.1 Lesson
More on ES6
Question:
ES6 Promises
Fill in the blanks to define a function that returns a Promise object.
Answer:
function foo() {
return new Promise((resolve, reject) => {
let result = getSomeResult();
if (result)
resolve('Success');
else
reject('Something went wrong');
});
}
Question:
Iterators & Generators
You can exit and re-enter generator functions, and their variable bindings will be saved across re-entrances.
Answer:
True
Question:
Modules
Fill in the blanks to import the following from "util/calc.js":
export const hit = (x, y, z) => {
return x * y + z / 2;
}
export const degree = 50;
Answer:
import * as calc from "util/calc";
calc.hit(1, 2, calc.degree);
Question:
Built-in Methods
What is the output of this code?
const arr = ['3', '5', '8'];
console.log(
arr.find(x => x == 8).repeat(2)
);
Answer:
88
64.1 Lesson
Module 8 Quiz
Question:
Which of the following is not one of the new ES6 features?
Answer:
Hoisting
Question:
Fill in the blanks to declare a constant num and an arrow function calc.
Answer:
const num = 5;
const calc = (x, y, z = num) => {
return x + y + z;
}
Question:
Fill in blanks to make the variable arr3 look like the following: [1, 2, 3, 4, 5, 6, 7, 8].
Answer:
const arr1 = [1, 2, 3];
const arr2 = [5, 6, 7, 8];
let arr3 = [...arr1, 4, ...arr2];
Question:
What is the output of the following code?
const arr1 = [1, 2, 3, 4, 5];
const arr2 = [...arr1, 6];
const func = (...rest) => {
console.log(rest.length);
}
func(...arr1);
func(...arr2);
Answer:
5 6
Question:
What is the output of this code?
const square = num => num * num;
console.log(square(6) + 6);
Answer:
42
Question:
Fill in the blanks to copy the user object to the newUser object by destructuring the name and age properties. Pass the value 9999 for the id property.
Answer:
const user = {
name: 'David',
age: 28,
id: 1234
};
let newUser = Object.assign({}, {
name,
age
} = user, {
id: 9999
});
console.log(newUser);
Question:
Fill in the blanks to get the following output:
zero = 0
one = 1
Answer:
let myMap = new Map();
myMap.set('zero', 0);
myMap.set('one', 1);
for (let [key, value] of myMap) {
console.log(`${key} = ${value}`);
}