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.
Embedded
<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; 
or 
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

Ratio and Proportion

175 men can dig a canal of 3150 meters long in 36 days. How many men are required to dig a canal of 3900 meters long in 24 days?

24 men working at 8 hours a day can do a piece of work in 15 days. In how many days can 20 men working at 9 hours a day do the same work?

10 men can lay a road of 75 Km long in 5 days. In how many days can 15 men lay a road of 45 Km long?

Rice costing Rs. 480/- is needed for 8 members for 20 days. What is the cost of rice required for 12 members for 15 days?

The mess charge for 35 students for 24 days is Rs. 6300/-. In how many days will the mess charges be Rs. 3375/- for 25 students?

Time and Work

18 men can dig a well in 10 days. After they have worked for 4 days, how many more men shall be employed to complete the work in 4 days from then?

If 80 men can do a piece of work in 10 days, how many men are required to do the same work in 4 days?

If 80 men can do a piece of work in 10 days, in how many days can 40 men do the same piece of work?

General Computer Knowledge

What kind of material does ‘IC’ in computers made of?

Physics

The force required to produce an acceleration of 4 m/s2 in an object of mass 9 kg is?

Biology

Some seeds have hooks and spines. It helps the seeds to__________?

Physics

Which of the following modes of heat transfer is faster?

Agriculture

Which of the following reproduces from underground stem?

Botany

Lichens are a symbiotic association of?

Physics

The unit of relative density is?

Problems on Ages

The ages of Gyanendra and Jitendra are in the ratio of 12:7 respectively. After 6 years, the ratio of their ages will be 3:2 respectively . find the difference in their ages?

Time and Work

X can do a piece of work in 20 days, while Y can do in 10 days. If Y worked at it for 8 days,then X can finish the remaining work in______.?

Coding-Decoding

In a certain code, BELIEF is written as AFKKDI. How is SELDOM written in that code?