Javascript Interview Questions and Answers – Part7

61.  What is the difference between “==” and “===”?
“==” checks equality only,
“===” checks for equality as well as the type.

62.  How can the OS of the client machine be detected?
The navigator.appVersion string can be used to detect the operating system on the client machine.

63. How to access the value of a textbox using JavaScript?

<!DOCTYPE html>
Full name: <input type="text" id="txtFullName" 
name="FirstName" value="Vikas Ahlawat">

There are following ways to access the value of the above textbox:

var name = document.getElementById('txtFullName').value;

we can use the old way:

var name = document.forms[0].FirstName.value;

Note: This uses the “name” attribute of the element to locate it.

64. Explain window.onload and onDocumentReady?
The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.
onDocumentReady loads the code just after the DOM is loaded. This allows early manipulation of the code.

65.  What are the ways of making comments in JavaScript?
// is used for line comments
ex:- var x=10; //comment text

*/ is used for block comments
var x= 10; /* this is
block comment example.*/

66. How will you explain closures in JavaScript? When are they used?
Closure is a locally declared variable related to a function which stays in memory when the function has returned.
For example:

function greet(message) {

function greeter(name, age) {
return name + " says howdy!! He is " + age + " years old";

// Generate the message
var message = greeter("James", 23);

// Pass it explicitly to greet

This function can be better represented by using closures
function greeter(name, age) {
var message = name + " says howdy!! He is " + age + " years old";
return function greet() {

// Generate the closure
var JamesGreeter = greeter("James", 23);
// Use the closure

67. How will you get the Checkbox status whether it is checked or not?
var status = document.getElementById(‘checkbox1’).checked;
will return true or false.

68. How can a value be appended to an array?
A value can be appended to an array in the given manner –
arr[arr.length] = value;

69. How to create arrays in JavaScript?
There are two ways to create array in JavaScript like other languages:
a) The first way to create array
Declare Array:

var names = new Array(); 
Add Elements in Array:-
names[0] = "Vikas";
names[1] = "Ashish";
names[2] = "Nikhil";

b) This is the second way:

var names = new Array("Vikas", "Ashish", "Nikhil");

70. If an array with name as “names” contain three elements, then how will you print the third element of this array?
Print third array element document.write(names[2]);

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 *

3 × nine =

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