Java Script Interview Questions and Answers

How do we get JavaScript onto a web page?

The script element can directly be added inside the body of the page. It should start with the tag <script> and end with </script> tag. The script can also be added to the head tag of the web page. Similarly the other way is by placing the script in a separate file which gets downloaded on the client's machine when the page is requested.
<SCRIPT LANGUAGE='JavaScript Version'> JavaScript statements </SCRIPT>
Stored externally
<SCRIPT src='abc.js' />

How we can access Elements using java script?

Each elements of JavaScript can be accessed by their names. To access the page, document element is used and to access the browser the window element is used in the script. This element's values are required for several computing reason say validation check. 
For example:
var myID = windows.document.formLogin.userID.value;

What does isNaN function do?
Return true if the argument is not a number.
What are the problems associated with using JavaScript, and are there JavaScript techniques that you discourage?

Browser version incompatibility is the biggest problem. It requires knowing how each scriptable browser version implements its object model. You see, the incompatibility rarely has to do with the core JavaScript language (although there have been improvements to the language over time); the bulk of incompatibility issues have to do with the object models that each browser version implements.
The second biggest can of worms is scripting connections between multiple windows. A lot of scripter's like to have little windows pop up with navigation bars or some such gizmos. But the object models, especially in the older browser versions, don't make it easy to work with these windows the minute you put a user in front of them--users who can manually close windows or change their stacking order.

How do you submit a form using JavaScript?

Use document.forms[0].submit();
0 refers to the index of the form's. if you have more than one form in a page, then the first one has the index 0, second has index 1 and so on. 

How to create arrays in JavaScript?

We can declare an array like this 
var scripts = new Array(); 
We can add elements to this array like this

scripts[0] = 'PHP';
scripts[1] = 'ASP';
scripts[2] = 'JavaScript';
scripts[3] = 'HTML';
We also can create an array like this 
var no_array = new Array(21, 22, 23, 24, 25);

What is the difference between an alert box and a confirmation box?

An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel. 
Alert ('Warning: Please enter an integer between 0 and 100.');
Confirm ('Do you really want to launch the missile?'); 

What is a prompt box/ input box?

A prompt box allows the user to enter input by providing a text box. 
Prompt ('What is your temperature?');

How about 2+5+'8'?

Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, its concatenation, so 78 is the result.

How to convert a string to a number using JavaScript?

You can use the parseInt() and parseFloat() methods. Notice that extra letters following a valid number are ignored. 
parseInt('100') ==> 100

How to convert numbers to strings using JavaScript?

You can append the number with an empty string 
var mystring = ' '+myinteger; 
var mystring = myinteger.toString();

What does break and continue statements do?
Continue statement continues the current loop (if label not specified) in a new iteration whereas break statement exits the current loop.
How to determine the state of a checkbox using JavaScript?

Determining the state of a checkbox in JavaScript var checkedP = window.document.getElementById('myCheckBox').checked;

Latest Updates


20% of a quantity is Rs 400, the quantity equals?

Time and Work

A certain piece of work can be completed by 12 men in 9 days. After they have worked for six days, six more men joined them. How many days will it take to complete the remaining work?

Ratio and Proportion

A certain sum was divided among A, B and C in the ratio 5 : 7 : 6. If B received Rs 4500 more than C, find C's share?

Problems on Ages

A is two years older than B who is twice as old as C. If the total of the ages of A, B and C be 27, the how old is A?

Time and Work

A and B can together finish a work in 30 days. They worked at it for 20 days and then B left. The remaining work was done by A alone in 20 more days. B alone can do the entire work in?


A retailer buys a washing machine marked at Rs 4800 and gets two successive discounts of 15% and 5%. If he spends Rs 124 on transportation and sells the washing machine at a gain of 13%, then find the selling price of the machine.

Boats and Streams

Speed of a boat in still water is 10 kmph, and speed of the stream is 5 Kmph. In how many minutes would the boat cover a distance of 5 km downstream?

Problems on Ages

The age of two persons differ by 2 years. If the sum of their ages is equal to the square root of 144 then find the age of the elder among the two person?

The age of A is six times the age of his son. A's father is 40 years older than him. Together, they are 118 years old. What is the age of A?


The average mark of 50 students is 75. If the marks obtained by one of the student had been written as 36 instead of 86, then the corrected average of marks is:


What is inode?

Problems on Ages

A group of 15 people has average age of 45 years. Two persons are excluded and the average of the remaining is increased by 5 years. What is the average age of the two persons who have been excluded?


In the world cup, Yuvraj has a batting average of 65 in 7 matches till semi-final. How much should Yuvraj score in the 8th match ie the final match to get a batting average of 85?

Problems on Trains

A train takes 8 sec to cross a 75 metre long platform at a speed of 90 km/h. What is the length of the train?

Alligation or Mixture

In what ratio must Rs 50 per kg salt be mixed with Rs 80 per kg salt to obtain a mixture worth of Rs 60 per kg?


Find the sum of the given series: 3 + 9 + 27 + 81 + 243 + 729 + 2187 + 6561


Find the average. 62, 54, 44, 36, 28 & 22


In an examination, 36% of the students failed in English and 40% failed in Hindi. If 20% of the students failed in both subjects, then the pass percentage is?

Latest Job Notifications

Jobs in Madhya Pradesh

राष्ट्रीय स्वास्थ्य मिशन मध्य प्रदेश National Health Mission MP(NRHM) - 5215 पद - 22/06/2021 अंतिम तिथि

Jobs in Punjab

पंजाब स्टेट पावर कॉर्पोरेशन लिमिटेड Punjab State Power Corporation Limited (PSPCL) - 2632 पद - 20/06/2021 अंतिम तिथि

Jobs in Chhattisgarh

स्वास्थ्य सेवा निदेशालय, छत्तीसगढ़ Department of Health & Family Welfare, Chhattisgarh - 267 पद - 26/06/2021 अंतिम तिथि

Government Jobs

दिल्ली सबऑर्डिनेट सर्विस सिलेक्शन बोर्ड Delhi Subordinate Services Selection Board(DSSSB) - 5807 पद - 03/07/2021 अंतिम तिथि

Jobs in Madhya Pradesh

राष्ट्रीय स्वास्थ्य मिशन मध्य प्रदेश National Health Mission MP(NRHM) - 2850 पद - 31/05/2021 अंतिम तिथि

Government Jobs

इंडियन पोस्ट सर्विस Indian Post Service - 4368 पद - 29/05/2021 अंतिम तिथि

दिल्ली सबऑर्डिनेट सर्विस सिलेक्शन बोर्ड Delhi Subordinate Services Selection Board(DSSSB) - 7236 पद - 24/06/2021 अंतिम तिथि

Banking Jobs

Reserve Bank of India (RBI) - 841 Posts - 15/03/2021 Last date

Institute of Banking Personnel Selection (IBPS) - CRP SPL-IX - 1163 Posts - 26/11/2019 Last date

Government Jobs

Reserve Bank of India (RBI) - 199 Posts - 11/10/2019 Last date