Javascript Interview Question and Answer

Categories: Java Script

Question:- What is JavaScript?

Answer:- JavaScript is a client-side and server-side scripting language inserted into HTML pages and is understood by web browsers. JavaScript is also an Object-based Programming language

 

Question:- Enumerate the differences between Java and JavaScript?

Answer:- 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 different intent. Java is an object-oriented programming (OOPS) or structured programming languages like C++ or C, whereas JavaScript is a client-side scripting language.

 

Question:- What are JavaScript Data Types?

Answer:- Following are the JavaScript Data types:

  1. Number
  2. String
  3. Boolean
  4. Object
  5. Undefined

 

Question:- Which is faster between JavaScript and an ASP script?

Answer:- JavaScript is faster. JavaScript is a client-side language,, and thus it does not need the assistance of the webserver 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).

 

Question:- What is negative Infinity?

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

 

Question:-  What are undeclared and undefined variables?

Answer:- Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.

Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.

 

Question:- What are global variables? How are these variable declared?

Answer:- Global variables are available throughout the length of the code so that it has no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.

 

Example:

 

// Declare a global: globalVariable = “Test”;

 

The problems faced by using global variables are the clash of variable names of local and global scope. Also, it is difficult to debug and test the code that relies on global variables.

 

 Question:- What is a prompt box?

Answer:- A prompt box is a box that allows the user to enter input by providing a text box. A label and box will be provided to enter the text or number.

 

Question:- What is ‘this’ keyword in JavaScript?

Answer:- ‘This’ keyword refers to the object from where it was called.

 

Question:- What is the working of timers in JavaScript?

Answer:- Timers are used to execute a piece of code at a set time or repeat the code in a given interval. This is done by using the functions setTimeout, setInterval, and clearInterval.

 

The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function repeatedly executes the given function in the mentioned delay and only halts when canceled. The clearInterval(id) function instructs the timer to stop.

 

Timers are operated within a single thread, and thus events might queue up, waiting to be executed.

 

Question:- Which symbol is used for comments in Javascript?

Answer:- // for Single line comments and

/* Multi

Line

Comment

*/

 

Question:- What is the difference between ViewState and SessionState?

Answer:-

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

 

Question:- What is === operator?

Answer:- === is called a strict equality operator, which returns true when the two operands have the same value without conversion.

 

Question:- Does JavaScript support automatic type conversion?

Answer:- Yes, JavaScript does support automatic type conversion. It is the common way of type conversion used by JavaScript developers

Question:- How to read and write a file using JavaScript?

Answer:- There are two ways to read and write a file using JavaScript

  1. Using JavaScript extensions
  2. Using a web page and Active X objects

 

Question:- What are all the looping structures in JavaScript?

Answer:- Following are looping structures in Javascript:

For

While

Do-while loops

 

Question:- What is called Variable typing in Javascript?

Answer:- Variable typing is used to assign a number to a variable. The same variable can be assigned to a string.

Example:

i = 10;

i = "string;"

Top articles
New JavaScript Features Published at:- Javascript Interview Question and Answer Published at:- Java Threads Interview Question and Answer for experienced Published at:- Java Collections Interview Question and Answer for freshers and experienced Published at:- Jakarta Server Page (JSP) programming language Interview Question and Answer Published at:-
R4Rin Team
The content on R4Rin.com website is created by expert teams.