Friday, 1 March 2013

Basic Javascript Technical Interview Questions and Answers for Web Developers - Objective and Subjective

Basic Javascript Technical Interview Questions and Answers for Web Developers - Objective and Subjective

In this tutorial on "Basic Javascript Technical Interview Questions and Answers For Web Developers", we will discuss some questions which are frequenty and commonly asked when you sit in a  technical interview on Javascript. So, if you are going for job interview and have mentioned javascript in your CV, you must go through the following javascript interview questions and answers. We will cover very basic things about javascript here like basic introdurction to javascript, datatypes in javascript, syntax of javascript and basic DOM events associated with javascript. Here goes the list of javascript interview questions and answers:

1. What is JavaScript?

JavaScript is a platform-independent,event-driven, interpreted client-side scripting language developed by Netscape Communications Corp. and Sun Microsystems.

JavaScript is a general-purpose programming language designed to let programmers of all skill levels control the behavior of software objects. The language is used most widely today in Web browsers whose software objects tend to represent a variety of HTML elements in a document and the document itself.

But the language is used with other kinds of objects in other environments. For example, Adobe Acrobat Forms uses JavaScript as its underlying scripting language to glue together objects that are unique to the forms generated by Adobe Acrobat.

Therefore, it is important to distinguish JavaScript, the language, from the objects it can communicate with in any particular environment.

When used for Web documents, the scripts go directly inside the HTML documents and are downloaded to the browser with the rest of the HTML tags and content.

2. How is JavaScript different from Java?

Don't be fooled by the term Java in both. Both are quite different technologies.

JavaScript was developed by Brendan Eich of Netscape; Java was developed at Sun Microsystems. While the two languages share some common syntax, they were developed independently of each other and for different audiences. Java is a full-fledged programming language tailored for network computing; it includes hundreds of its own objects, including objects for creating user interfaces that appear in Java applets (in Web browsers) or standalone Java applications. In contrast, JavaScript relies on whatever environment it's operating in for the user interface, such as a Web document's form elements.
JavaScript was initially called LiveScript at Netscape while it was under development. A licensing deal between Netscape and Sun at the last minute let Netscape plug the "Java" name into the name of its scripting language. Programmers use entirely different tools for Java and JavaScript. It is also not uncommon for a programmer of one language to be ignorant of the other. The two languages don't rely on each other and are intended for different purposes. In some ways, the "Java" name on JavaScript has confused the world's understanding of the differences between the two. On the other hand, JavaScript is much easier to learn than Java and can offer a gentle introduction for newcomers who want to graduate to Java and the kinds of applications you can develop with it.

3. What is the official JavaScript website?

This is a trick question used by interviewers to evaluate the candidate’s knowledge of JavaScript. Most people will simply say is the official website.

The truth is- there is no official website for Javascript you can refer to. It was developed by Brendan Eich for Netscape. It was based on the ECMAScript language standard; ECMA-262 being the official JavaScript standard.

4. What’s relationship between JavaScript and ECMAScript?

ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.

5. What are the various datatypes in javascript?


6. What boolean operators does JavaScript support?

&&, || and !

7. What is negative infinity?

It’s a number in JavaScript, derived by dividing negative number by zero.

8. Is it possible to check if a variable is an object?

Yes, it is possible to do so. The following piece of code will help achieve the same.

if(abc && typeof abc === "object") {
console.log('abc is an object and does not return null value');

9. Can you explain what isNaN function does?

isNaN function will check an argument and return TRUE (1) if the argument does not seem to be a number.

10. How do you convert numbers between different bases in JavaScript?

Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);

11. What is the difference between undefined value and null value?

undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value.

Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.

12. What is the difference between “==” and “===”?

While “==” checks only for equality, “===” checks for equality as well as the type.

13. Differentiate between “var a=2” and “a =2”

The major difference between the two is that one variable is local and the other is global. “var” basically defines the scope of the variable.

When we add var to a variable value assignment, javascript ensures that the variable is confined to whichever function it is assigned to and does not collide with the same name variable within another function.

When we don’t use var, then it is declared as a global function and chances of collision can happen. So it’s always advisable to use “var” before variable value assignment. If needed use an anonymous function for closure.

14.  What is Javascript namespacing? How and where is it used?

Using global variables in Javascript is evil and a bad practice. That being said, namespacing is used to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you’ve attached all further methods, properties and objects. It promotes modularity and code reuse in the application.

15. What does "1"+2+4 evaluate to?

Since 1 is a string, everything is a string, so the result is 124.

16. How about 2+5+"8"?

Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.

17. How to create arrays in JavaScript?

We can declare an array like this
var scripts = new Array();
We can add elements to this array like this
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
Now our array scrips has 4 elements inside it and we can print or access them by using their index number. Note that index number starts from 0. To get the third element of the array we have to use the index number 2 . Here is the way to get the third element of an array.
We also can create an array like this
var no_array = new Array(21, 22, 23, 24, 25);
18. How do you create a new object in JavaScript?

var obj = new Object(); or var obj = {};

19. How do you assign object properties?

obj["age"] = 17 or obj.age = 17

20. What’s a way to append a value to an array?

arr[arr.length] = value;

21. What is this keyword?

It refers to the current object.
22. How many looping structures can you find in javascript?

If you are a programmer, you know the use of loops. It is used to run a piece of code multiple times according to some particular condition. Javascript being a popular scripting language supports the following loops

do-while loop

23. Are javascript and jQuery different?

jQuery is a quick as well as concise JavaScript Library that simplifies HTML document traversing, animating, event handling, & Ajax interactions for the purpose of quick web development needs. So although they are not entirely different, both are not the same either!

24. Explain the strict mode in Javascript.

The strict mode ensures that if functions are not properly thought it, those are disabled. It also kept a check on potentially unsafe actions and throw errors when it happens.

25. Is it possible for you to write a one line JavaScript code that concatenates all strings passed into a function?

The following function should help in producing the desired result

function concatenate()
  return String.prototype.concat.apply('', arguments);

26. Explain Javascript closures.

A basic overview of javascript closures is that it is a stack-frame which is not de-allocated when the function returns.

27. What is event bubbling?

Event bubbling describes the behavior of events in child and parent nodes in the Document Object Model (DOM); that is, all child node events are automatically passed to its parent nodes. The benefit of this method is speed, because the code only needs to traverse the DOM tree once. This is useful when you want to place more than one event listener on a DOM element since you can put just one listener on all of the elements, thus code simplicity and reduction. One application of this is the creation of one event listener on a page’s body element to respond to any click event that occurs within the page’s body.

28. Difference between window.onload and onDocumentReady?

The onload event does not fire until every last piece of the page is loaded, this includes css and images, which means there’s a huge delay before any code is executed.

That isnt what we want. We just want to wait until the DOM is loaded and is able to be manipulated. onDocumentReady allows the programmer to do that.
29. How do you change the style/class on any element?

document.getElementById(“myText”).style.fontSize = “20″;
document.getElementById(“myText”).className = “anyclass”;

30. How is form submission possible via javascript?

We can achieve the desired form submission by using the function document.forms[0].submit().

It must be noted that the 0 in the piece of code given above refers to the form index. Say we have multiple forms on a particular page. To make all the form procession unique, we give each form index numbers. The first form will have the index number as 0. The second form will have an incremented number, 1. The third will have 2 and so on.

31. How JavaScript timers work? What is a drawback of JavaScript timers?

Timers allow you to execute code at a set time or repeatedly using an interval. This is accomplished with the setTimeout, setInterval, and clearInterval functions. The setTimeout(function, delay) function initiates a timer that calls a specific function after the delay; it returns an id value that can be used to access it later. The setInterval(function, delay) function is similar to the setTimeout function except that it executes repeatedly on the delay and only stops when cancelled. The clearInterval(id) function is used to stop a timer. Timers can be tricky to use since they operate within a single thread, thus events queue up waiting to execute.

32. How to get CheckBox status whether it is checked or not?


if it will be checked you will get true else false.

33. How to get value from a textbox?


34. How to get value from dropdown (select) control?


35. How to get value from RadioButtonList control?

Here id is the name property of the RadioButtonList
function GetRadioButtonValue(id)
            var radio = document.getElementsByName(id);
            for (var ii = 0; ii < radio.length; ii++)
                if (radio[ii].checked)

36. How to detect the operating system on the client machine?

In order to detect the operating system on the client machine, the navigator.appVersion
string (property) should be used.


  1. The original javascript was designed for client side and server side scripting. Although javascript is a popular client side scripting language, the server side, like nodejs is quickly becoming popular.

  2. Nice set of questions

  3. Thank u so much... really very informative article. Please post some questions for HTML5 and CSS3 also.

  4. Nice set of every question and ans.


  6. If you really answer that to somebody who has ANY KIND OF KNOWLEDGE, you're fucked, for this article is wrong in soooo many ways. Please don't give advice if you have no clue yourself ...

    1. really???

    2. Well:

      4. What’s relationship between JavaScript and ECMAScript?

      ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.

      That's completely wrong. For example, IE's implementation of ECMAScript is called JScript. ECMAScript != JavaScript.

  7. Really nice one. It help a lot to understand few conecpts like Bubbling, time handle..etc.. GOOD ONE

  8. Hi We must leave the comments for the sake of understanding only ... Please don't use any bad language to define the post.....

  9. Nice questions for the interview on JavaScript. Have a look onto more questions at Questions on JavaScript

  10. good collection of question its very usefull for interview purpose

  11. Very Good blog For JavaScript , Very Useful For Basic Learning Java Script
    Thank You So much

  12. Good question. But can you cover some advanced topic in detail like inheritance and closure. different types of object creation method as Douglas Crockford explained.

  13. hai happy new year.your provided excelent interview quetions

  14. clear the lots of doubts

  15. cool thanks ...

  16. If you are applying for the post of JavaScript engineer and you expect such questions.......

    No question on classes, inheritance. Objects. Function overriding.
    Name-spacing, scoping of variables.....

  17. Create a simple web design for all type of audience but use fresh colors and layout to make better Lead generation and Increased conversion rate.
    Saudi Arabian Web Design Companies

  18. Great article.... Thanks for this type of article....

    But please add more questions in this series...

    I have seen this type of article which is also a great article

    you can check it...

    For More questions Follow the link

  19. very nice blog for interview and learning programming language java script.

  20. If someone is looking a Job In Noida and Delhi NCR , then I am suggesting required opening for Php Web Developer
    in TheIncrcle.

  21. Thanks for all your information, Website is very nice and informative content.
    i like play games friv online and play games2girls 2 online free and play game friv games and games 2 girls ! have fun!

  22. I love all the posts, I really enjoyed, I would like more information about this, because it is very nice., Thanks for sharing.
    download free descargar whatsapp and download baixar whatsapp online and descargar whatsapp gratis , baixar whatsapp gratis

  23. Hello, just wanted to say, I loved this article. It was practical.
    Keep on posting!
    download descargar facebook gratis para Android celular and download free descargar facebook apk and descargar facebook gratis , descarga facebook

  24. Great info. I love all the posts, I really enjoyed, I would like more information about this, because it is very nice., Thanks for sharing.
    download facebook movel, baixar Facebook movel, baixar facebook. Facebook chat, baixar whatsapp, fazer o download whatsapp baixar para Android, iPhone. Últimas Facebook

  25. I am very happy to read this. Appreciate your sharing
    Versión en facebook en español descargar a los países hablan Español: facebook entrar direto agora , facebook en español para and facebook entrar direto

  26. Hello, just wanted to say, I loved this article. It was practical.
    Keep on posting!
    The place to play all unblocked games at school online. Here you can find every blocked games such as: unblockedgames , unblocked games happy , unblocked games 77 ,

  27. Tks very much for your post.

    Avoid surprises — interviews need preparation. Some questions come up time and time again — usually about you, your experience and the job itself. We've gathered together the most common questions so you can get your preparation off to a flying start.

    You also find all interview questions at link at the end of this post.

    Source: Interview Questions & Answers:

    Best rgs

  28. Thanks for sharing this quality information with us. I really enjoyed reading. I think I need it.
    Games for girls|
    Kizi 1|
    Kizi 2

  29. Thanks for sharing the information. It is very useful for my future. keep sharing
    Kizi 123|
    Friv 234|

  30. Thanks for your great article friend, i get new information, new ideas to do somethings, i hope you will share again, i keep waiting for next post, thanks.
    Friv 4
    Kizi 3

  31. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write.
    Friv 10

  32. Thank you very much for your post.Its pretty interesting. I appreciate your blogs and look forward for your next blog.
    Bank Coaching Centres in Chennai T Nagar

  33. I am very happy to read this. Very interesting! Thanks you . You have posted a trust worthy blog keep sharing.
    i like play games happy wheels online and play happy wheels 2 games and agar , fireboy watergirl , fireboy and watergirl

  34. You need to kill time, you need entertainment. Refer to our website. hope you get the most comfort.
    Thanks you for sharing!
    Friv Games

  35. Excellent post!!! In this competitive market, customer relationship management plays a significant role in determining a business success. That too, cloud based CRM product offer more flexibility to business owners to main strong relationship with the consumers. Salesforce Training Institutes in Chennai | Salesforce Training in Chennai

  36. I am extremely impressed with your writing skills and also with the layout on your blog
    Chip Level Training in Hyderabad

  37. Thanks for sharing with us that awesome article you have amazing blog.....
    Chip Level Training in Hyderabad

  38. Excellent information with unique content and it is very useful to know about the information based on blogs.`
    Chip Level Training in Hyderabad

  39. very informative & different one....
    I would like to share the information to get jobs easily
    Chip Level Training in Hyderabad

  40. You are stressed and tired, you need entertainment. Refer to our website. hope you get the most comfortable.
    Kizi 4

  41. you'd have time to look these kids active. Please visit our website and let us play the game interesting.
    Thanks for sharing !
    Friv 10
    Kizi 10
    Yepi 2

  42. This is something special! never seen this before! thank you
    Friv 100

  43. thank you for your interest in welcome visit
    Friv 4

  44. You need to kill time, you need entertainment. Refer to our website. hope you get the most comfort.
    Thanks for sharing !
    Friv 5
    Kizi 1
    Yepi 3

  45. New attractive game . I will play it every day
    Friv 2