Toptal

You might also like

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

HIRE A DEVELOPER

APPLY AS A DEVELOPER

LOGIN

CALL US: 888.604.3188

19 Great JavaScript Interview


Questions*
Like

988

Share

86

Share

Tweet 456

186

SUBMIT AN INTERVIEW QUESTION

Looking for JavaScript experts? Check out Toptal's JavaScript developers.

What is the significance of, and reason for, wrapping the entire content of a JavaScript source file in a
function block?
View the answer

What will the code below output to the console and why?
var myObject = {
foo: "bar",
func: function() {
var self = this;
console.log("outer func: this.foo = " + this.foo);
console.log("outer func: self.foo = " + self.foo);
(function() {
console.log("inner func: this.foo = " + this.foo);
console.log("inner func: self.foo = " + self.foo);
}());
}
};
myObject.func();

View the answer

What is the significance, and what are the benefits, of including


source file?

'use strict'

at the beginning of a JavaScript

View the answer

Consider the two functions below. Will they both return the same thing? Why or why not?
function foo1()
{
return {
bar: "hello"
};
}
function foo2()
{
return

converted by Web2PDFConvert.com

{
bar: "hello"
};
}

View the answer

What will the code below output? Explain your answer.


console.log(0.1 + 0.2);
console.log(0.1 + 0.2 == 0.3);

View the answer

Discuss possible ways to write a function

isInteger(x)

that determines if

is an integer.

View the answer

Write a one-line function (less than 80 characters) that returns a boolean indicating whether or not a string is
a palindrome.
View the answer

In what order will the numbers 1-4 be logged to the console when the code below is executed? Why?

(function() {
console.log(1);
setTimeout(function(){console.log(2)}, 1000);
setTimeout(function(){console.log(3)}, 0);
console.log(4);
})();

View the answer

Consider the following code snippet:


for (var i = 0; i < 5; i++) {
var btn = document.createElement('button');
btn.appendChild(document.createTextNode('Button ' + i));
btn.addEventListener('click', function(){ console.log(i); });
document.body.appendChild(btn);
}

(a) What gets logged to the console when the user clicks on Button 4 and why?
(b) Provide one or more alternate implementations that will work as expected.
View the answer

What will the code below output to the console and why ?
console.log(1 + "2" + "2");
console.log(1 + +"2" + "2");
console.log(1 + -"1" + "2");
console.log(+"1" + "1" + "2");
console.log( "A" - "B" + "2");
console.log( "A" - "B" + 2);

converted by Web2PDFConvert.com

console.log( "A" - "B" + 2);

View the answer

What will the code below output to the console and why?
var arr1 = "john".split('');
var arr2 = arr1.reverse();
var arr3 = "jones".split('');
arr2.push(arr3);
console.log("array 1: length=" + arr1.length + " last=" + arr1.slice(-1));
console.log("array 2: length=" + arr2.length + " last=" + arr2.slice(-1));

View the answer

The following recursive code will cause a stack overflow if the array list is too large. How can you fix this and
still retain the recursive pattern?
var list = readHugeList();
var nextListItem = function() {
var item = list.pop();
if (item) {
// process the list item...
nextListItem();
}
};

View the answer

What is a potential pitfall with using


be avoided?

typeof bar === "object"

to determine if

bar

is an object? How can this pitfall

View the answer

What will the code below output to the console and why?
(function(){
var a = b = 3;
})();
console.log("a undefined? " + (typeof a === 'undefined'));
console.log("b undefined? " + (typeof b === 'undefined'));

View the answer

What is

NaN

? What is its type? How can you reliably test if a value is equal to

NaN

View the answer

Write a

sum

method which will work properly when invoked using either syntax below.

console.log(sum(2,3)); // Outputs 5
console.log(sum(2)(3)); // Outputs 5

View the answer

converted by Web2PDFConvert.com

What is a closure in JavaScript? Provide an example.


View the answer

When, why, and how would you use a closure in JavaScript? Provide examples.
View the answer

What is the output out of the following code? Explain your answer.
var a={},
b={key:'b'},
c={key:'c'};
a[b]=123;
a[c]=456;
console.log(a[b]);

View the answer

* There is more to interviewing than tricky technical questions, so these are intended merely as a guide. Not every A candidate worth hiring will be able to
answer them all, nor does answering them all guarantee an A candidate. At the end of the day, hiring remains an art, a science and a lot of work.

Submit an interview question


You may submit a question with or without an answer, but those submitted with answers are more likely to be posted. Submitted questions and
answers are subject to review and editing, and may or may not be selected for posting, at the sole discretion of Toptal, LLC.

Name

Email

Enter your question here

Enter your answer here

Fields marked with an asterisk (*) are required

Comment
I agree with the Terms and Conditions of Toptal, LLC's Privacy Policy

converted by Web2PDFConvert.com

Submit a Question

Looking for JavaScript experts? Check out Toptal's JavaScript developers.

Ryan J. Peterson

Alejandro Hernandez

United States

Argentina

Croatia

Ryan is a top architect, entrepreneur, and


developer with a proven competency in
building cloud-scalable, extensible
software and systems that can be
maintained and expanded upon over time
as business systems and requirements
change and adapt to market demands or
pivots in core business direction.

Alejandro got his Engineering degree


seven years ago, and since then he has
been working for several software
companies of all sizes from all around the
globe as a freelancer. Currently, he enjoys
working as a technical lead on JavaScript
projects where his deep understanding of
architecture and theory is most impactful.

Tomislav is a software engineer, technical


consultant and architect with over 10 years
of experience. He specializes in full-stack,
highly scalable, real-time JavaScript and
Node.js applications, with past experience
in C#, Java, and Ruby. He is an agile
Kanban practitioner who loves to
collaborate on development projects.

JavaScript
CoffeeScript

PHP

HTML5

CakePHP

JavaScript

Tomislav Capan

jQuery

JavaScript

C#

Node.js

Node.js
HIRE TOMISLAV

HIRE RYAN

HIRE ALEJANDRO

At Toptal, we connect the best


developers all over the world.
Join the Toptal community.

TRENDING ON BLOG
From the Ground Up: How I Built the Developer's Dream Keyboard
Blockchain: The Technology Powering Bitcoin
Advanced Java: A Guide to Class Reloading
Reverse Engineering The Private API: Hacking your Couch
Context Aware Apps and Complex Event Processing
Managing the View State with React

Exclusive access to top developers

HIRE A DEVELOPER

OR

APPLY AS A DEVELOPER

NAVIGATION

CONTACT

SOCIAL

Why
How
What
Clients
Team
Community
Blog
Resources
Videos
Client reviews
Developer reviews
Contact
FAQ

Apply for work


Become a partner
Send us an email
Call 888.604.3188

Facebook
Twitter
Google+
GitHub
Dribbble

Copyright 2010 - 2015 Toptal, LLC

Policy, Terms of Service


Privacy Policy,
converted by Web2PDFConvert.com

converted by Web2PDFConvert.com

You might also like