Java Script Interview QUESTIONS

Exam NameJava Script Interview QUESTIONS
DescriptionJava Script Interview QUESTIONS contains the questions from various interview of IT industry.These questions are helpful to crack the IT interview.
Exam TypeMASTER EXAM
Authenticity3
creatorPayal(381)

Back to Parent Category
Create QuestionPDF  
.
Question: What is JavaScript?

Answer:JavaScript is a scripting language most often used for client-side web development.


Question: What is the difference between JavaScript and Jscript?

Answer:Both JavaScript and Jscript are almost similar. JavaScript was developed by Netscape. Microsoft reverse engineered Javascript and called it JScript.


Question: Is JavaScript case sensitive?

Answer:Yes!
A function getElementById is not the same as getElementbyID.


Question: What are the types used in JavaScript?

Answer:String, Number, Boolean, Function, Object, Null, Undefined.


Question: What is the difference between "==" and "==="?

Answer:"==" checks equality only,
"===" checks for equality as well as the type.


Question: What are the boolean operators supported by JavaScript?

Answer:And Operator: &&
Or Operator: ||
Not Operator: !


Question: How to access the value of a textbox using JavaScript?

Answer:var name = document.getElementById('textboxID').value;


Question: What are the ways of making comments in JavaScript?

Answer:// is used for line comments
ex:- var x=10; //comment text

/*
*/ is used for block comments


Question: How will you get the Checkbox status whether it is checked or not?

Answer:var status = document.getElementById('checkboxID').checked;


Question: How to create arrays in JavaScript?

Answer: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");



Question: How do you submit a form using JavaScript?

Answer:Use document.forms[0].submit();


Question: What does isNaN function do?

Answer:It returns true if the argument is not a number.


Question: What is the use of Math Object in JavaScript?

Answer:The math object provides you properties and methods for mathematical constants and functions.
ex:-
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


Question: What do you understand by this keyword in JavaScript?

Answer: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 window object is the 0-level context):

var obj = { outerWidth : 20 };

function say() {
alert(this.outerWidth);
}

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



Question: What does "1"+2+4 evaluate to?

Answer:Since 1 is a string, everything is a string, so the result is 124.


Question: What does 3+4+"7" evaluate to?

Answer:Since 3 and 4 are integers, this is number arithmetic, since 7 is a string, it is concatenation, so 77 is the result.


Question: How do you change the style/class on any element using JavaScript?

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

OR

document.getElementById(“myText”).className = “anyclass”;


Question: What is an object in JavaScript, give an example?

Answer:An object is just a container for a collection of named values:

var man = new Object();
man.name = 'Vikas Ahlawat';
man.living = true;
man.age = 27;


Question: Name any two JavaScript functions which are used to convert nonnumeric values into numbers?

Answer:Number()
parseInt()
parseFloat()


Question: Does JavaScript Support automatic type conversion, If yes give example.

Answer:Yes! Javascript support automatic type conversion. You should take advantage of it, It is most common way of type conversion used by Javascript developers.

var s = '5';
var a = s*1;
var b = +s;
typeof(s); //"string"
typeof(a); //"number"
typeof(b); //"number"