Java Script Interview Question and Answer

9. Name some of the JavaScript features.
Lightweight, interpreted programming language.
Designed for creating network-centric applications.
Complementary to and integrated with Java.
Complementary to and integrated with HTML.
Open and cross-platform.

10. How would you compare two objects in JavaScript?
JavaScript has two different approaches for testing equality. Primitives like strings and numbers are compared by their value, while objects like arrays, dates, and user defined objects are compared by their reference. This means it compares whether two objects are referring to the same location in memory. Equality check will check whether two objects have same value for same property. To check that, you can get the keys for both the objects. If the number of properties doesn’t match, these two objects are not equal. Secondly, you will check each property whether they have the same value. If all the properties have same value, they are equal.
The method determines whether two values are the same value., value2); determines whether two values are the same value. Two values are the same if one of the following holds:
both undefined
both null
both true or both false
both strings of the same length with the same characters
both the same object
both numbers and
both +0
both -0
both NaN
or both non-zero and both not NaN and both have the same value

11. What is the difference between ViewState and SessionState?
‘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.
SessionState persist the data of particular user in the server. This data available till user close the browser or session time completes. View State are valid mainly during postbacks and information is stored in client only. Viewstate are valid for serializable data only.

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

13. Explain the differences between Java and JavaScript?
Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for the different intent. Java is an object – oriented programming (OOPS) or structured programming language like C++ or C whereas JavaScript is a client-side scripting language and it is said to be unstructured programming.

14. What is the use of Void(0)?
Void(0) is used to prevent the page from refreshing and parameter “zero” is passed while calling.
Void(0) is used to call another method without refreshing the page.

15. What is the data type of variables of in JavaScript?
All variables in the JavaScript are object data types.

16. What is the difference between an alert box and a confirmation box?
An alert box displays only one button which is the OK button.
But a Confirmation box displays two buttons namely OK and cancel.