• RSS Unknown Feed

    • An error has occurred; the feed is probably down. Try again later.
  • Meta

JavaScript – Beginning Interview Questions

In doing numerous technical interviews of Internet Application Developers, I’ve discovered that most of these candidates consider their JavaScript skills to be at an “expert” level or they feel their JavaScript skills are “very strong.” In the course of the interview, however, it is often discovered that the candidates only have a cursory understanding of the JavaScript programming language. Based on my experience, I have written 20 questions that someone claiming to know JavaScript should be able to answer:

What have you used JavaScript for?
Typical answers include form validations, user action confirmations, updating an Internet page dynamically and other such answers. I usually ask this question first just to get the candidate talking about JavaScript and see if they have in fact used JavaScript for something.

How do you access an element in an HTML document with JavaScript?
Give the element an ID attribute and then use JavaScript’s getElementById() function to access that element.

How do you determine how many characters are in a JavaScript string?
With the length property of the JavaScript string object.

What datatypes are supported by JavaScript?
Number, String, Undefined, null, Boolean. At a minimum, the candidate should identify Number and String.

How do you create a date in JavaScript?
With the Date object: new Date()

Where does JavaScript date object pull it’s date from?
From the client machine.

What does the isNaN function do?
Returns true is the value provided is not a numeric value and false if the number provided is a numeric value.

What is the difference between JavaScript and Java?
They are completely different languages.

How do you comment JavaScript code?
For single-line comments, begin the line with consecutive forward slashes (//). To comment a block of code, wrap it with /* code */.

What is the JavaScript concatenation operator?
The plus sign.

How do you call an external JavaScript file?
With the script tag, using the src attribute to reference the path of the JavaScript file.

How do you create a function in JavaScript?
Use the function statement.

How do you get the item selected in a dropdown select list?
With the selectedIndex property

How do you open a new window?
With window.open

How do you remove all options from a dropdown select list?
By setting the length property of the dropdown select list to 0.

Demonstrate the syntax for writing a FOR loop.
Need an answer similar to:
for (i=1;i<=LoopNumber;i++)
{
//do something
}

How do you determine the length of an array?
With the length property of the array object

How do you load a new URL in a browser?
With the location or href property of the window or document object.

What are the different usages of equal signs?
One (=) is for assignment. Two (==) is for equality. Three (===) is for strict comparison.

What is ++ used for
It is the increment operator. It adds one to a value.

12 Responses

  1. Not that you are asking for advice, but I’d replace:

    How do you access an element in an HTML document with JavaScript?

    with:

    How do you write dynamic text in an HTML document with JavaScript?

    in my experience, experts use or have written their own utility class to use functionality like this across all browsers. Further so – it could steer you into a conversation about cross browser code.

    Just a thought.

  2. Great Article.
    Thanks for sharing with us.

    Pinal Dave
    ( http://www.SQLAuthority.com )

  3. […] Vincent famous author of Joey JavaScript and Guru of JavaScript has written JavaScript – Beginning Interview Questions. Read them and you will find out yourself that do you really know JavaScript or it is just an […]

  4. Very good article. It will be really great if you add some stuff about AJAX related JavaScript questions like How can you call a page synchronously through JavaScript?
    Anyway, great stuff.

    Namwar Rizvi,
    http://blog.namwarrizvi.com

  5. Namwar,

    Thanks for your comment. I will be posting an Ajax article containing interview questions by the end of this month.

  6. Nice article. Obviously you’re now going to get candidates that can answer these! How about a couple of additions:

    1. What’s the difference between null and Undefined? (to spot the philosophers:-)
    2. How would you use JavaScript in an object-oriented manner?
    3. What do you think about data typing in JavaScript?

  7. Kevin,

    Thanks. Here’s hoping we do get some candidates that can answer these now. That would be an improvement. 🙂

    In response to your finely suggested questions:

    1) Good idea. This question should definitely be added if they are getting the other correct.
    JavaScript Difference Between null and defined
    2) If they claim to know OO principles this can be asked.
    3) Data typing is another good suggestion. JavaScript Data Types

  8. Interesting article… but I’m a very novice javascript user and knew how to do most of those things. Maybe I missed something but anyone who claims to be even a novice at JS should know most of the things on this list. Neat article however.
    – Leif

    P.S. For an example of what I mean, here’s some of my javascript experience (which is very minimal, but uses many of the techniques described in this article):
    video.greenmangames.vze.com, affiliates.greenmangames.vze.com, graphics.greenmangames.vze.com, colorpicker.greenmangames.vze.com, citator.greenmangames.vze.com… etc.

  9. Leif,

    Indeed a novice JavaScript user should know how to do the items mentioned in the article. Hence the title “JavaScript Beginning Interview Questions.” I just find it ironic that many who claim advanced JavaScript skills fail to answer these questions.

  10. “How do you load a new URL in a browser?
    With the location or href property of the document object.”

    Wrong. The correct answer is: With the location or with the location.href property of the window object.

  11. “How do you access an element in an HTML document with JavaScript?
    Give the element an ID attribute and then use JavaScript’s getElementById() function to access that element.”

    This is only one of the methods, and the modern trend is rather to use the more dynamical methods getElementsByTagName(‘tag’)[index], childNodes, nextSibling, previousSibling, parentNode… and to reduce the id refrence to a minimum necessary.

  12. The use of the window object to open a new URL is explained in the link that goes to the detailed article. I have updated this post to match.

Leave a comment