Javascript Interview Questions and Answers – Part2

11. What are global variables? How are these variable declared and what are the problems associated with using them?
Global variables are those that are available throughout the length of the code, that is, these have 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.
// Declare a global globalVariable = “Test”;
The problems that are 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.

12. What is a prompt box?
A prompt box is a box which allows the user to enter input by providing a text box.  Label and box will be provided to enter the text or number.

13. What is ‘this’ keyword in JavaScript?
‘This’ keyword is used to point at the current object in the code. For instance: If the code is presently at an object created by the help of the ‘new’ keyword, then ‘this’ keyword will point to the object being created.

14. Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?
Timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. 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 is used to repeatedly execute the given function in the mentioned delay and only halts when cancelled. 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.

15. Which symbol is used for comments in Javascript?
// for Single line comments and
/*   Multi

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

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

18. Name all the datatypes available in javascript?
The different datatypes are:

  • Number
  • String
  • Boolean
  • Function
  • Object
  • Null
  • Undefined

19. What are “undeclared” and “undefined” variables?
Undeclared variables are declared during run time and those variables cannot be declared in the program.
Undefined variables are the variables that are declared before assigning value to the program.

20. How can the style/class of an element be changed?
It can be done in the following way:

document.getElementById(“myText”).style.fontSize = “20?;


document.getElementById(“myText”).className = “anyclass”;


Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)

Leave a Reply

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

two + 5 =

Popup Dialog Box Powered By :
  • RSS
  • Facebook
  • Google+
  • Twitter