JavaScript interview questions

Want to become an expert in cracking JavaScript interview questions/Front end interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public JavaScript interview questions test.

To use our service for testing developers, purchase one of the paid plans for companies.


1. Date
JavaScript Strings Public

Write a function that converts user entered date formatted as M/D/YYYY to a format required by an API (YYYYMMDD). The parameter "userDate" and the return value are strings.

For example, it should convert user entered date "12/31/2014" to "20141231" suitable for the API.

Easy  
10min
Solve question

2. Ensure
JavaScript Language Public

Modify the ensure function so that it throws an error if called without arguments or an argument is undefined. Otherwise it should return the given value.

Easy  
3min
Solve question

3. RemoveProperty
JavaScript Language Public

Implement the removeProperty function that takes an object and a property name and does the following:

  • If object obj has property prop, it removes the property from the object.
  • If the property has been removed, it returns true; otherwise it returns false.
Easy  
7min
Solve question

4. Loop
JavaScript Bug fixing DOM manipulation Public

Function appendChildren should add a new child div to each existing div. New divs should be decorated by calling decorateDiv.

For example, after appendChildren is executed, the following divs:

  <div id="a">
    <div id="b">
    </div>
  </div>

should take the following form (assuming decorateDiv does nothing):

  <div id="a">
    <div id="b">
      <div></div>
    </div>
    <div></div>
  </div>

The code below should do the job, but for some reason it goes into an infinite loop. Fix the bugs.

Hard  
15min
Solve question

5. Closures
JavaScript Bug fixing Closures Public

Fix the bugs in the registerHandlers function. An alert should display anchor's zero-based index within a document instead of following the link.

For example, in the document below, the alert should display "2" when Google anchor is clicked since it is the third anchor element in the document and its zero-based index is 2.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test page</title>
  </head>
  <body>
    In my life, I used the following web search engines:<br/>
    <a href="//www.yahoo.com">Yahoo!</a><br/>
    <a href="//www.altavista.com">AltaVista</a><br/>
    <a href="//www.google.com">Google</a><br/>
  </body>
</html>
Hard  
15min
Solve question

If you feel ready, take one of our timed public JavaScript interview questions tests:

  • HTML/CSS, JavaScript online test (Easy / Hard)
  • HTML/CSS, JavaScript, and Bootstrap online test (Easy / Hard)
  • HTML/CSS, JavaScript, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, C#, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, Java, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, PHP, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, Python, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, Ruby, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, SQL, and C# Algorithms online test (Easy / Hard)
  • HTML/CSS, JavaScript, SQL, and Java Algorithms online test (Easy / Hard)
  • JavaScript online test (Easy / Hard)
  • JavaScript and SQL online test (Easy / Hard)
Not exactly what you are looking for? Go to our For developers section.