Javascript Interview Questions and Answers – Part8

71. What is event bubbling and capturing in JavaScript?
Event bubbling is series of events when : An event is triggered on the inner most element first and then it triggers on the parent elements in nested order.
DOM elements could be nested inside each other. The handler of the parent works even if you click on it’s child. Event bubbling can make this happen.
Event Capturing is the opposite of bubbling where the event is triggered on the outer most element and then it triggers the inner children in nested order.

72.  How do you submit a form using JavaScript?
Use document.forms[0].submit();

73.  What is a closure in JavaScript?
JavaScript allows you to declare a function within another function, and the local variables still can be accessible even after returning from the function you called.
In other words, a closure is the local variables for a function which is kept alive after the function has returned.
An example :

function goodMorning(name) {
var text = ‘Good Morning ‘ + name; // local variable
var goodMorningAlert = function() { alert(text); }
return sayAlert;

var goodMorningAlert2 = goodMorning(‘Bob’);

In the example above, when goodMorningAlert2() will be executed, you will see output as an alert with “Good Morning Bob”.

In short, in JavaScript, if you use the function keyword inside another function, you are creating a closure.

74. What does isNaN function do?
It returns true if the argument is not a number.

document.write(isNaN("Hello")+ "<br>");
document.write(isNaN("2013/06/23")+ "<br>");
document.write(isNaN(123)+ "<br>");

The output will be:

75.  What is the difference between GET and POST methods in HTML form?
When you use a GET method, key and values will be appended at the end of the URL as a query string. GET method is not recommended to use when you are passing sensitive data over the internet.
While sending data, the GET method appends the data to the URL. And the length of a URL is limited. Maximum URL length is 2048 characters supported by latest browsers.
POST is used to pass sensitive data as it’s not appended and displayed within the URL. There is no limitation as to how much data can be passed using a POST method.

76. What is the use of Math Object in JavaScript?
The math object provides you properties and methods for mathematical constants and functions.

var x = Math.PI; // Returns PI
var y = Math.sqrt(16); // Returns the square root of 16
var z = Math.sin(90); Returns the sine of 90

77. What do you understand by this keyword in JavaScript?
In JavaScript the this is a context-pointer and not an object pointer. It gives you the top-most context that is placed on the stack. The following gives two different results (in the browser, where by-default the windowobject is the 0-level context):

var obj = { outerWidth : 20 };

function say() {

say();//will alert window.outerWidth
say.apply(obj);//will alert obj.outerWidth

78. What does “1”+2+4 evaluate to?
Since 1 is a string, everything is a string, so the result is 124.

79. What does 3+4+”7″ evaluate to?
Since 3 and 4 are integers, this is number arithmetic, since 7 is a string, it is concatenation, so 77 is the result.

80. How do you change the style/class on any element using JavaScript?

document.getElementById(“myText”).style.fontSize = “10";


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 *

× 4 = four

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