May 16, 2021
JavaScript Interview Question and Answers

JavaScript Interview Question and Answers

JavaScript Interview Question and Answers

JavaScript Online Training1. What is JavaScript?

ANS: 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 can be–and is–used with other kinds of objects in other environments.

2. Who Developed JavaScript?

ANS: Brendan Eich of Netscape;

3. Does JavaScript have the concept level scope?

Ans: No, JavaScript does not have block level scope, all the variables declared inside a function possess the same level of scope unlike C, C++, Java.

4. What are JavaScript types?

Ans: Number, String, Boolean, Function, Object, Null, Undefined.

5. How is JavaScript different from Java?

ANS: The two languages don’t rely on each other and are intended for different purposes.

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.’

JavaScript relies on whatever environment it’s operating in for the user interface, such as a Web document’s form elements.

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.

6. What is variable typing in JavaScript?

Ans: It is perfectly legal to assign a number to a variable and then assign a string to the same variable as follows example
i = 10;
i = “string”;
This is called variable typing

7. What does undefined value mean in JavaScript?

Ans: Undefined value means the variable used in the code doesn’t exist or is not assigned any value or the property doesn’t exist.

8. What is undefined value means in JavaScript?

ANS: There can be multiple reasons of having undefined values

1. Object does not exist. Like you create an object of a control which does not exists in your page and when you access it, it is undefined.
2. No value is assigned to the object.
3. If you are trying to access a property which does not exists for the object.

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

Ans: A Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null.
B. type of undefined variable or property returns undefined whereas type of null value returns object.

10. What is undefined variable?

ANS: Variables which are declared but not assigned any value is called undefined variable.

11. What’s relationship between JavaScript and ECMAScript?

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

12. What boolean operators does JavaScript support?

Ans: &&, || and!

13. What looping structures are there in JavaScript?

Ans: for, while, do-while loops, but no for each.

14. How can JavaScript make a Web site easier to use?

ANS: JavaScript’s greatest potential gift to a Web site is that scripts can make the page more immediately interactive, that is, interactive without having to submit every little thing to the server for a server program to re-render the page and send it back to the client.

15. Difference between VBScript and JavaScript?

ANS:  JavaScript case sensitive where’s VBScript not case sensitive.

JavaScript will be run on client side where’s VBScript will be run on server side.

JavaScript is the default scripting language for browsers but VBScript must be specified as the scripting language.

JavaScript has cross-platform support from all popular browsers while VBScript is supported MS IE only.

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

ANS: 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);

17. How do you create a new object in JavaScript?

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

18. How to read and write a file using JavaScript?

ANS: I/O operations like reading or writing a file is not possible with client-side JavaScript. However, this can be done by coding a Java applet that reads files for the script.

19. What is the difference between Client side JavaScript and Server side JavaScript?

ANS: Client-Side JavaScript (CSJS)
It is JavaScript that enables the enables web pages on browsers to run active online content.

Server-Side JavaScript (SSJS)
It is JavaScript that enables back-end access to databases, file systems, and servers

20. In, JavaScript which method is used to find the character at a position in a string?

ANS: charAt ().

21. Which JavaScript feature uses JAR files?

ANS: Object signing.

22. What can JavaScript programs do?

ANS: Generation of HTML pages on-the-fly without accessing the Web server. The user can be given control over the browser like User input validation Simple computations can be performed on the client’s machine The user’s browser, OS, screen size, etc. can be detected Date and Time Handling.

23. What is the data type of variables of in JavaScript?

ANS: All variables are of object type in JavaScript.

24. What are a fixed-width table and its advantages in JavaScript?

ANS: Fixed width tables are rendered by the browser based on the widths of the columns in the first row, in JavaScript resulting in a faster display in case of large tables.
Use the CSS style table-layout: fixed to specify a fixed width table.
If the table is not specified to be of fixed width in JavaScript, the browser has to wait till all data is downloaded and then infer the best width for each of the columns. This process can be very slow for large tables.

25. How to embed JavaScript in a web page?

ANS: JavaScript code can be embedded in a web page in two ways:

1) <script langugage=”javascript”> </script>
2) <script type=”text/javascript”></script>

For JavaScript Online Training please visit