W3 Docs ES6 Basic Course Free Certification | ES6 Basic Quiz Answers 2022

Quiz ES6 Basic

Start Quiz

Test your knowledge with W3docs’ basic quiz of ES6. Pass the test and get a Certificate of achievement!

The Test

The test contains 20 questions and there is no time limit. The test is not official, it’s just a nice way to see how much you know about ES6.

Count Your Score

You will get 5% for each correct answer. At the end of the Quiz, your total score will be displayed out of 100% maximum score.

Start Quiz

Enrich your knowledge

At the end of the quiz you can see all the questions with the right answers. There will also be notes about the answers which will lead you to the appropriate page on the platform to enrich your knowledge. Read our HTML tutorial if you are not sure that you are ready for the quiz.

Quiz Answers

Constants are block-scoped variables.

True

False

Ans. True

The statement “let” declares a block scope local variable.

True

False

Ans. True

What is the final value of “obj” in the following example?

const obj = { foo: 1 };
obj.bar = 2;

{ foo: 1 }

{ foo: 1, bar: 2 }

{ foo: 1, 2: bar }

None of the above

Ans. { foo: 1, bar: 2 }

Rest is a new way for functions to handle an arbitrary number of parameters. Can you guess what the mysterious “a” variable holds?

function mystery(…params) {
return params;
}
let a = mystery(1,23,4);

“a” is undefined

“a” becomes [1,23,4]

“a” becomes “1 23 4”

“a” becomes 1 23 4

Ans. “a” becomes [1,23,4]

String interpolation is a much-needed new feature that is finally available in JavaScript. See the example below. Is there anything wrong with it?

let name = ‘Harry’;
let occupation = ‘wizard’;
console.log(Hi! My name is ${name}. I'm a ${occupation}.);

Nothing wrong with the example. This is how the feature works in ES6.

The example is wrong. You can’t break a String into lines in JavaScript.

The example is wrong. You can’t embed variables in String in JavaScript.

None of the above.

Ans. Nothing wrong with the example. This is how the feature works in ES6.

What value will this expression return?

let x, { x: y = 1 } = { x }; y;

{ x: 1 }

1

{ x : 1 }

“undefined”

Ans. 1

What will this function return?

(function() {
let f = this ? class g { } : class h { };
return [ typeof f, typeof h ];
})();

[“undefined”, “undefined”]

[“function”, “function”]

[“function”, “undefined”]

Error

Ans. [“function”, “undefined”]

What is a Promise()?

Tool for managing asynchronous control flow. A promise represents an operation expected to complete in the future.

The opposite of Amateurmise().

Something you say, when you want someone to believe you.

None of the above.

Ans. Tool for managing asynchronous control flow. A promise represents an operation expected to complete in the future.

What value will this expression return?

[…[…’…’]].length

3

6

9

Error

Ans. 3

What will the result of this expression be?

typeof (new (class F extends (String, Array) { })).substring

Error

“undefined”

“object”

“function”

Ans.
“undefined”

What will this function return?

(function() {
if (false) {
let f = { g() => 1 };
}
return typeof f;
})()

Undefined

“object”

“function”

Error

Ans. Error

What result will this expression have?

typeof (function* f() { yield f })().next().next()

“generator”

“object”

“function”

Error

Ans. Error

Why is super used?

Is used for creating and initializing an object.

It’s a simple function.

Is used as an “object” which calls the parent class.

Is used as a “function” which calls the parent’s constructor.

Ans. Is used as a “function” which calls the parent’s constructor.

ES6 introduces a special “const” declaration. Do you know what it does?

const PI = 3.14;
console.log(PI) //Prints 3.14

It is exactly the same as let.

It is used to define math-related variables.

Const turns variables into constants, and they can’t be changed.

Ans. Const turns variables into constants, and they can’t be changed.

ES6 gives you a number of new methods for operating with Strings. Which one replaces this annoying piece of code?

let some_text = “some string”;
if(some_text.indexOf(‘str’) !=-1){
return true;
}

some_text.repeat(‘str’);

some_text.endsWith(‘str’);

some_text.includes(‘str’);

Ans. some_text.includes(‘str’);

ES6 gives an alternative way to assign variables. Can you guess what the below code does?

let a = 12, b = 3;
[a, b] = [b, a];

Makes both a and b equal 12.

Swaps the values inside a and b, without using extra variables.

Creates an array that contains a and b.

Ans. Swaps the values inside a and b, without using extra variables.

What is stored in the triangle array?

let point = [1,3], segment = [point,[5,5]], triangle = […segment,[1,8]];

23

[1,3,5,5,1,8]

[ [1,3], [5,5], [1,8] ]

Ans. [ [1,3], [5,5], [1,8] ]

Is this a valid code?

class Slave { // … };
const slave = Slave();

Yes

No

Ans. No

error: Content is protected !!