Interview questions for Java script

JavaScript also abbreviated as JS, is a high level server side programming language. JavaScript is widely used all over the world to build various web applications, which means there are huge opportunities available for the JavaScript programming. To build a career in JavaScript programming, candidates need to crack the interview in which they are asked for various JavaScript interview questions and answers.

1. What is the difference between Java & JavaScript?

Java
Java is an OOP programming language.

It creates applications that run in a virtual machine or browser.

Java code needs to be compiled.

Java script

JavaScript is an OOP scripting language.

The code is run on a browser only.

JavaScript code are all in the form of text.

2. What is the use of is Nan function?

Nan function returns true if the argument is not a number otherwise it is false.

3. What is negative infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

4. What is JavaScript?

JavaScript is a lightweight, interpreted programming language with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages. The general-purpose core of the language has been embedded in Netscape, Internet Explorer, and other web browsers.

5. Between JavaScript and an ASP script, which is faster?

JavaScript is faster. JavaScript is a client-side language and thus it does not need the assistance of the web server to execute. On the other hand, ASP is a server-side language and hence is always slower than JavaScript. Javascript now is also a server side language (nodejs).

6. What are the data types supported by JavaScript?

The data types supported by JavaScript are:
• Undefined
• Null
• Boolean
• String
• Symbol
• Number
• Object

7. What is argument objects in JavaScript & how to get the type of arguments passed to a function?

JavaScript variable arguments represents the arguments that are passed to a function. Usingtypeof operator, we can get the type of arguments passed to a function. For example −
1
2
3
4
5
6 function func(x){
console.log(typeof x, arguments.length);
}
func(); //==> “undefined”, 0
func(7); //==> “number”, 1
func(“1”, “2”, “3”); //==> “string”, 3

8. What are the scopes of a variable in JavaScript?

• The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.
• Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code.
• Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

9. What is the rest parameter and spread operator?

Both rest parameter and spread operator were introduced in the ES6 version of java script.

Rest parameter

It provides an improved way of handling parameters of a function.

Using the rest parameter syntax, we can create functions that can take a variable number of arguments.

Any number of arguments will be converted into an array using the rest parameter.

It also helps in extracting all or some parts of the arguments.

Rest parameter can be used by applying three dots (…) before the parameters.

10. What is the purpose of ‘This’ operator in JavaScript?

The JavaScript this keyword refers to the object it belongs to. This has different values depending on where it is used. In a method, this refers to the owner object and in a function, this refers to the global object.

11. What is the difference between View State and Session State?

• ‘ViewState’ is specific to a page in a session.
• ‘SessionState’ is specific to user specific data that can be accessed across all pages in the web application.

12. What is === operator?

=== is called as strict equality operator which returns true when the two operands are having the same value without any type conversion.

13. Name the different types of groups of data types that are used in JavaScript and define them?

There are two basic groups of data types –
• Reference type- These are complex types of data which can mainly include dates and strings.
• Primitive type- These are the types of data that include numbers

14. Name the problems that are associated with the use of global variables?

Even though global variables are easy to use, these have some shortfalls. While using this type of variables, the problem of clashing of the variable names of different global and local scope occurs. The code that is often relied on the global variable also gets difficult to be tested and debugged.

15. How are JavaScript and ECMA Script related?

ECMA Script are like rules and guideline while Javascript is a scripting language used for web development.

16. What is name spacing in JavaScript and how is it used?

Name spacing is used for grouping the desired functions, variables etc. under a unique name. It is a name that has been attached to the desired functions, objects and properties. This improves modularity in the coding and enables code reuse.

17. Which Company developed JavaScript?

Netscape company had developed the JavaScript Programming Language.

18. What type of variables we use in JavaScript?

We use object data type variables in JavaScript.

19. Explain about escape characters?

Espace characters are used to handle the special characters without breaking the code in javascript. It uses a black slash for different characters like single and double quotes, newline and so on
• ’ single quote
• backslash
• ’’ double quote
• n newline
• b backspace
• t tab
• f form feed

20. What is an event bubbling in JavaScript?

Event bubbling is a way of event propagation in the HTML DOM API, when an event occurs in an element inside another element, and both elements have registered a handle for that event. With bubbling, the event is first captured and handled by the innermost element and then propagated to outer elements. The execution starts from that event and goes to its parent element. Then the execution passes to its parent element and so on till the body element.

21. What is NaN in JavaScript?

NaN is a short form of Not a Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number. When a string or something else is being converted into a number and that cannot be done, then we get to see NaN.

22. How do JavaScript primitive/object types passed in functions?

One of the differences between the two is that Primitive Data Types are passed By Value and Objects are passed By Reference.
• By Value means creating a COPY of the original. Picture it like twins: they are born exactly the same, but the first twin doesn’t lose a leg when the second twin loses his in the war.
• By Reference means creating an ALIAS to the original. When your Mom calls you “Pumpkin Pie” although your name is Margaret, this doesn’t suddenly give birth to a clone of yourself: you are still one, but you can be called by these two very different names.

leave your comment


Your email address will not be published. Required fields are marked *