Engineering, Design, Marketing, and More

ECMAScript6 interview questions

The most popular questions

Use our complementary questions and answers to filter and hire the best. Questions crowdsourced by our clients, answers by Punch. We provide these complementary questions to help our clients more quickly create tests for potential hires at their organizations.

Get a question answered
Punch offers four divisions of services: design, engineering, staffing, and demand

Interview questions for your next interview

Question
What is ECMAScript 6 or ES 6?
Answer
ECMAScript is the “proper” name for the language commonly referred to as JavaScript. ES6 is also referred to as “Harmony” and it is the sixth major release of the ECMAScript language specification.
Question
What is the best way to create Private Properties in ES6?
Answer
It can only be done for Scoped Accessed in Objects by using Symbols. Symbols are unique, you can't gain access to one from the outside except with reflection (like privates in Java/C#) but anyone who has access to the Symbol on the inside can use it for key access.

E.g.var property = Symbol();
class Something {
constructor(){
this[property] = "test";
}
}
var instance = new Something();
console.log(instance.property); //=> undefined, can only access with access to theSymbol

Find developers today

Hire a Punch engineer

Punch offers four divisions of services: design, engineering, staffing, and demand. Our four divisions form the core of our People Forward Approach.

Contact us
Find developers today
Question
What is the ES6 Map feature?
Answer
The Map object is a simple key/value map. Any value (both objects and primitive values) may be used as either a key or a value. Syntax [key, value]. e.g.hash = new Map()
hash.set("hello", 42)
hash.set(1, 34);

console.log(hash); //Map {"hello" => 42, 1 => 34}
Question
How would you sort an ES6 Map Object?
Answer
var map = new Map();
map.set('2-1', "foo");
map.set('0-1', "bar");
map.set('3-1', "baz");
var mapAsc = new Map([...map.entries()].sort());
console.log(mapAsc);
Question
How would you filter an Array of Objects in ES6?
Answer
Array of objects can be filtered by using the method explained in this example:var family = [{"name":"Jack", "age": 26},
{"name":"Jill", "age": 22},
{"name":"James", "age": 5 },
{"name":"Jenny", "age": 2 }];
family.filter(person => person.age > 18); //Filters the Array of Objects to condition set
Question
What's the correct way to use Destructuring Assignment in ES6?
Answer
In ES5 e.g.var jsonMiddleware = require('body-parser').json
var body = req.body, // body has username and password
username = body.username,
password = body.password
In ES6:var {jsonMiddleware} = require('body-parser')
var {username, password} = req.body
Question
What's the correct way to use ES6 in a project?
Answer
ES6 is finalized, but not fully supported by all browsers (e.g., ES6 Firefox support). To use ES6, we need to use a compiler like Babel. You can run it as a standalone tool or use with your build system. There are Babel plugins for Grunt, Gulp and Webpack.

Here’s a Gulp example. Install the plugin:$ npm install --save-dev gulp-babelIn gulpfile.js, define a task build that takes src/app.js and compiles it into the build folder:var gulp = require('gulp'),
babel = require('gulp-babel')

gulp.task('build', function () {
return gulp.src('src/app.js')
.pipe(babel())
.pipe(gulp.dest('build'))
})
Question
What are Promises in ES6?
Answer
Promises have been a controversial topic. There were a lot of promise implementationswith slightly different syntax. q, bluebird, deferred.js, vow, avow, jQuery deferred to name just a few. Others said we don’t need promises and can just use async, generators, callbacks, etc. Gladly, there’s a standard Promise implementation in ES6 now!

Let’s consider a rather trivial example of a delayed asynchronous execution with setTimeout():setTimeout(function(){
console.log('Yay!')}, 1000)
We can re-write the code in ES6 with Promise:var wait1000 = new Promise(function(resolve, reject) {
setTimeout(resolve, 1000)})
.then(function() {
console.log('Yay!')
})
Or with ES6 arrow functions:var wait1000 = new Promise((resolve, reject)=> {
setTimeout(resolve, 1000)})
.then(()=> {
console.log('Yay!')
})
So far, we’ve increased the number of lines of code from three to five without any obvious benefit. That’s right. The benefit will come if we have more nested logic inside of thesetTimeout() callback:setTimeout(function(){
console.log('Yay!')
setTimeout(function(){
console.log('Wheeyee!')
}, 1000)
}, 1000)
Can be re-written with ES6 promises:var wait1000 = ()=> new Promise((resolve, reject)=> {setTimeout(resolve, 1000)})
wait1000()
.then(function() {
console.log('Yay!')
return wait1000()
})
.then(function() {
console.log('Wheeyee!')
});

Ask a question

Ask a question, and one of our engineers will answer it.

We keep our questions nice and simple to be useful for everyone, and we may not answer or publish every question.

Your number is stored privately and never shared.
By submitting a question, you agree to our terms.
Request sent. Thank you!
Send another one