JavaScript Interview Questions and Answers

JavaScript is the most used Client Side Scripting Language for web development. The Interview question and answers for the JavaScript are explain in detail and with example where applicable. These JavaScript interview questions covers commonly asked question in interview.

1. What is JavaScript?

JavaScript is most popular web programming language(client side server scripting language) and it was developed by NetScape during 1995 . It is client side scripting language and JavaScript is used for interactive web design.

2. Difference between Java and JavaScript?

  • Java is a static language whereas JavaScript is dynamic language.
  • Java is compiled language and JavaScript is interpreted language
  • Java requires virtual machine to run it applets and JavaScript requires web browser.
  • Java is secure because its source code is hidden whereas JavaScript source code is easily accessible.

3. Write Hello World program using JavaScript?

Hello World program using JavaScript is given below:

4. Explain functions in JavaScript?

Functions are used to perform certain task. JavaScript function consists of certain part of code for perform certain function.
function YourFunction(parameter1, parameter 2, ….)
{
You function code
}

5. Write a program to demonstrate JavaScript function?

Program for JavaScript Functions is given below:

6. Can we hide JavaScript in old browser? How?

Yes, JavaScript can be hide in older browsers(which does not support JavaScript) by adding <!—at the start of the code and –> at the end of the JavaScript code.

7. What is ECMAScript?

ECMAScript is a client side scripting language. There are popular client side scripting language which are completely based on ECMAScript like JavaScript, Jscript and ActionScript.

8. What are the popup boxes in JavaScript?
JavaScript supports multiple popup with different functionality. Some of the examples of JavaScript PopUp boxes are alert box, prompt box, confirm box etc.

9. What is Alert in JavaScript?

Alert box is can be used for confirmation of users and by clicking Ok, the popup will disappear.

10. Explain prompt box with an example?

Unlike alert and confirm box, prompt box lets users to enter the value and if users click Ok, then it will returns the user entered valued. If the click cancel, then the prompt box is disappear.

11. How confirm box is used in JavaScript?

A confirm box is used for used for action i.e. confirming. The popup box consists of two options, OK(which returns true or accept) and Cancel(which return false or rejects).

12. What is the difference between alert, confirm and prompt box?

Alert box has only one button Ok whereas confirm and prompt box has two button Ok and Cancel. Alert Ok button lets users for confirmation of details or certain other information whereas confirm and prompt boxes has two buttons, Ok and Cancel( Ok means users accept/true and Cancel means false/rejects). But prompt box lets users to enter input in the popup box whereas Alert and Confirm does not.

13. What are events in JavaScript?

HTML events can be interacted with JavaScript to make interactive web design. Some of the commonly used HTML events in JavaScript are onClick, OnLoad, onchange etc.

14. Define Arrays in JavaScript? How to declare arrays in JavaScript?

In JavaScript, arrays can stores multiple values in single variable. Example for Array using JavaScript is:

15. Write a JavaScript program to display time and date?

Using JavaScript programming language, we can display the current date and time in the web browser. The program to display the date and time is given below:

16. How to detect the browser of the user using JavaScript?

The users browsers can be detected by using navigator.appVersion. It returns complete details about users browser, OS and version.

17. Explain Windows Navigator?

In JavaScript, windows.navigator tells the information about the users/visitors browsers and it platform

18. Name some of the Windows Navigator?

Some of the example of Windows Navigator are navigator.appName, navigator.appCodeName, navigator.platform

19. How to declare variable using JavaScript?

Variable in JavaScript can be declared using var keyword. The declaration for JavaScript variable is given below:var a=5;

20. What are the scopes of variable?

According to the use of the variable, it scope varies. Global variable can is accessible to all the function and whereas local variable is only accessible within the function.