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

Indian Geography

What is the approximate distance between earth and the moon?

Indian History

In which year was the battle of ‘Koregaon Bhima’ fought?

The approach that is very useful in organizing the content in history is.

General Knowledge of India

NITI Aayog stands for _____.

General Knowledge of MP

India’s first Ramayan art museum was established at?

Errors Identification

Read the sentence carefully and choose the option that has an error in it:
The management’s trusted employee was suspected of stealing large sum of money.

Read the sentence carefully and choose the option that has an error in it:
The teacher asked the child to repeat again because he spoke feebly.

Fill in the blank

Fill in the blank with the most appropriate preposition in the given sentence.
Let’s sit _________ the shade of this beautiful tree.

Choose the most appropriate determiner for the given sentence.
________of what he said was very sensible.

Substitution

Choose the option that substitutes the given phrase appropriately.
A work of art made by carving

Correct sentence

Choose the option that best transforms the sentence into its Indirect form:
‘What country do you come from?’ said the police officer.

Alternative Phrase

Choose the option that best explains the highlighted expression:
All human beings have feet of clay.

Fill in the blank

Choose an appropriate modal for the given sentence:
My doctor said that I_____ stop smoking as one of my lungs got infected.

Choose the appropriate prepositions for the given sentence:
My parents have been married ________ forty-nine years, but you can still see the love ________ their eyes.

Choose the appropriate conjunction for the given sentence:
______ it rains, the college will declare the holiday.

Antonyms

Choose the appropriate antonym for the highlighted word in the given sentence.
The family protracted their visit by several days.

Tenses

Choose the appropriate tenses to fill in the blanks in the given sentence:
Please _________ a noise. Ritu __________ to sleep.

Synonyms

Choose the appropriate synonym for the highlighted word in the given sentence.
Does he really expect us to believe such a flimsy excuse?