Vous êtes sur la page 1sur 7

11/21/2014

LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject

Sign up for our free weekly Web Developer


11,031,940
Newsletter.
members 79,161 online

home

articles

quick answers

discussions

Sign in

features

community

help

Searchforarticles,questions,tips

Articles Web Development Client side scripting General

Latest JavaScript Interview Questions and Answers PDF


Vikas ahlawat www.tutoriz.com, 3 Apr 2014

CPOL

Rate this:

4.64 55 votes

JavaScript Interview Questions Answers

Info
First Posted

14 Jul 2013

Views

310,415

Bookmarked

73 times

Introduction
Below is the list of latest and updated JavaScript interview questions and their answers for freshers as well as
experienced users. These interview questions will help you to prepare for the interviews, So let's start....

JavaScript Interview Questions for both Experienced Programmers and Freshers


1 What is JavaScript?
Ans:JavaScript is a scripting language most often used for clientside web development.
2 What is the difference between JavaScript and Jscript?
Ans:Both JavaScript and Jscript are almost similar. JavaScript was developed by Netscape. Microsoft reverse
engineered Javascript and called it JScript.
3 How do we add JavaScript onto a web page?
Ans:There are several way for adding JavaScript on a web page, but there are two ways which are commonly used
by developers
If your script code is very short and only for single page, then following ways are the best:
a You can place <scripttype="text/javascript"> tag inside the <head> element.
Code
Collapse | Copy Code

<head>
<title>PageTitle</title>
<scriptlanguage="JavaScript"type="text/javascript">
varname="VikasAhlawta"
alert(name);
</script>
</head>

b If your script code is very large, then you can make a JavaScript file and add its path in the following way:
Code
Collapse | Copy Code

<head>
<title>PageTitle</title>
<scripttype="text/javascript"src="myjavascript.js"></script>
</head>

4 Is JavaScript case sensitive?


Ans:Yes!
A function getElementByIdis not the same as getElementbyID.
5 What are the types used in JavaScript?
Ans:String, Number, Boolean, Function, Object, Null, Undefined.
6 What are the boolean operators supported by JavaScript? And Operator: &&
Or Operator: ||

http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers

1/7

11/21/2014

LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject
Not Operator: !
7 What is the difference between == and ===?
Ans:
== checks equality only,
=== checks for equality as well as the type.
8 How to access the value of a textbox using JavaScript?
Ans: ex:
Code
Collapse | Copy Code

<!DOCTYPEhtml>
<html>
<body>
Fullname:<inputtype="text"id="txtFullName"
name="FirstName"value="VikasAhlawat">
</body>
</html>

There are following ways to access the value of the above textbox:
Collapse | Copy Code

varname=document.getElementById('txtFullName').value;
alert(name);

or:
we can use the old way:
Collapse | Copy Code

document.forms[0].mybutton.
varname=document.forms[0].FirstName.value;
alert(name);

Note: This uses the "name" attribute of the element to locate it.
9 What are the ways of making comments in JavaScript?
Ans:
Collapse | Copy Code

//isusedforlinecomments
ex:varx=10;//commenttext
/*
*/isusedforblockcomments

ex:
Collapse | Copy Code

varx=10;/*thisis
blockcommentexample.*/

10 How will you get the Checkboxstatus whether it is checked or not?


Ans:
Collapse | Copy Code

varstatus=document.getElementById('checkbox1').checked;
alert(status);

will return trueor false.


11 How to create arrays in JavaScript?
Ans:There are two ways to create array in JavaScript like other languages:
a The first way to create array
Declare Array:
Code
Collapse | Copy Code

varnames=newArray();
AddElementsinArray:
names[0]="Vikas";
names[1]="Ashish";

http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers

2/7

11/21/2014

LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject
names[2]="Nikhil";

b This is the second way:


Collapse | Copy Code

varnames=newArray("Vikas","Ashish","Nikhil");

12 If an array with name as "names" contain three elements, then how will you print the third element of
this array?
Ans: Print third array element document.write(names[2]);
Note: Array index starts with 0.
13 How do you submit a form using JavaScript?
Ans:Use document.forms[0].submit();
14 What does isNaN function do?
Ans: It returns trueif the argument is not a number.
Example:
Code
Collapse | Copy Code

document.write(isNaN("Hello")+"<br>");
document.write(isNaN("2013/06/23")+"<br>");
document.write(isNaN(123)+"<br>");

The output will be:


Collapse | Copy Code

true
true
false

15 What is the use of Math Object in JavaScript?


Ans: The math object provides you properties and methods for mathematical constants and functions.
ex:
Code
Collapse | Copy Code

varx=Math.PI;//ReturnsPI
vary=Math.sqrt(16);//Returnsthesquarerootof16
varz=Math.sin(90);Returnsthesineof90

16 What do you understand by this keyword in JavaScript?


Ans: In JavaScript the this is a contextpointer and not an object pointer. It gives you the topmost context that
is placed on the stack. The following gives two different results in the browser, where bydefault the window
object is the 0level context:
Collapse | Copy Code

varobj={outerWidth:20};

functionsay(){
alert(this.outerWidth);
}

say();//willalertwindow.outerWidth
say.apply(obj);//willalertobj.outerWidth

17 What does "1"+2+4 evaluate to?


Ans: Since 1is a string, everything is a string, so the result is 124.
18 What does 3+4+"7" evaluate to?
Ans: Since 3and 4are integers, this is number arithmetic, since 7is a string, it is concatenation, so 77is the
result.
19 How do you change the style/class on any element using JavaScript?
Ans:
Code
Collapse | Copy Code

document.getElementById(myText).style.fontSize=10";

http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers

3/7

11/21/2014

LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject
or
Collapse | Copy Code

document.getElementById(myText).className=anyclass;

20 Does JavaScript support foreach loop?


Ans: JavaScript 1.6ECMAScript 5th Edition support foreach loop,
See example here http://jsfiddle.net/gpDWk/
21 What looping structures are there in JavaScript?
Ans: for, while, dowhileloops
22 What is an object in JavaScript, give an example?
Ans: An object is just a container for a collection of named values:
// Create the manobject
Code
Collapse | Copy Code

varman=newObject();
man.name='VikasAhlawat';
man.living=true;
man.age=27;

23 How you will add function as a property in a JavaScript object? Give an example.
Ans:

Article

Code
Collapse | Copy Code

Browse Code varman=newObject();


man.name='VikasAhlawat';
Stats
man.living=true;
Revisions 17 man.age=27;
man.getName=function(){returnman.name;}
Alternatives console.log(man.getName());//Logs'VikasAhlawat'.

Research

Choosing the Rig


Charting
Component for
Your...

Comments 28

24 What is the similarity between the 1st and 2nd statement?


1st: varmyString=newString('male');//Anobject.
Tagged as 2nd: varmyStringLiteral='male';//Primitivestringvalue,notanobject.
Ans: Both will call String()constructor function
Javascript You can confirm it by running the following statement:
Interview

Collapse | Copy Code

console.log(myString.constructor,myStringLiteral.constructor);

25 What will be the output of the following statements?


Related Articles

Code

SQL Server Interview


Questions and
varmyString='Vikas'//Createaprimitivestringobject.
Answers Complete
varmyStringCopy=myString;//Copyitsvalueintoanewvariable.
List Download
varmyString=null;//Manipulatethevalue
console.log(myString,myStringCopy);
SQL Server 2008
Ans://Logs'nullVikas'
Interview Questions
and Answers

Collapse | Copy Code

26 Consider the following statements and tell what would be the output of the logs statements?

SQL SERVER Data


Warehousing
Interview Questions
varprice1=10;
and Answers
varprice2=10;
Complete List varprice3=newNumber('10');//Acomplexnumericobjectbecausenewwasused.
Download
console.log(price1===price2);
console.log(price1===price3);
SOA Interview
Questions: Part 1

Collapse | Copy Code

Ans:

CodeProject
interviews Anders
console.log(price1===price2);//Logstrue.
Hejlsberg andconsole.log(price1===price3);/*Logsfalsebecauseprice3
Steve
Lucco, Microsoft
containsacomplexnumberobjectandprice1
Technical Fellows
isaprimitivevalue.*/

Collapse | Copy Code

27 What would be the output of the following statements?


Go to top

http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers

Collapse | Copy Code

4/7

11/21/2014

LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject

Go to top
varobject1={same:'same'};
varobject2={same:'same'};
console.log(object1===object2);

Ans: // Logs false, JavaScript does not care that they are identical and of the same object type.
When comparing complex objects, they are equal only when they reference the same object i.e., have the same
address. Two variables containing identical objects are not equal to each other since they do not actually point
at the same object.
28 What would be the output of the following statements?
Code
Collapse | Copy Code

varobject1={same:'same'};
varobject2=object1;
console.log(object1===object2);

Ans: // Logs true


29 What is this?
Collapse | Copy Code

varmyArray=[[[]]];

Ans: Three dimensional array


30 Name any two JavaScript functions which are used to convert nonnumeric values into numbers?
Ans:
Collapse | Copy Code

Number()
parseInt()
parseFloat()

Code
Collapse | Copy Code

varn1=Number(Helloworld!);//NaN
varn2=Number();//0
varn3=Number(000010);//10
varn4=Number(true);//1
varn5=Number(NaN);//NaN

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


Ans: Yes! Javascript support automatic type conversion. You should take advantage of it, It is most common way
of type conversion used by Javascript developers.
Ex.
Collapse | Copy Code

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

*Question31 suggested by Florian Rappl

License
This article, along with any associated source code and files, is licensed under The Code Project Open License
CPOL

Share
EMAIL

http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers

5/7

11/21/2014

LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject

About the Author

Comments and Discussions


You must Sign In to use this message board.
Search Comments
Profile popups

Spacing Relaxed

Noise Medium

Layout Normal

Go
Per page 25

Update

First Prev Next

My vote of 4

Novakovi

Thanks

Girish Nama

My Vote 5

Shemeemsha RA

6Oct14 20:52

My vote of 5

Sibeesh KV

16Sep14 0:07

Very simple for the beginners

rvasif

3Apr14 6:41

Please improve the answer to question 7

gwag

3Apr14 1:40

My vote of 1

Member 10394796

2Apr14 8:15

Nice job

chait301

4Mar14 4:02

Great and Simple

Endalew

17Oct13 12:41

Thanks

oddadmix

30Sep13 5:38

My vote of 3

DhruvSakalley

8Sep13 15:33

My vote of 4

Member 10004231

30Aug13 0:52

My vote of 5

teeoneone

28Aug13 0:32

My vote of 4

Nitij Kumar

27Aug13 2:26

My vote of 5

Juhi Paunikar

My vote of 5

Sk. Tajbir

Another BIG mistake

Florian Rappl

25Aug13 20:35

Vikasahlawat24

25Aug13 21:12

Re: Another BIG mistake


Re: Another BIG mistake

Florian Rappl

3Nov14 4:18
17Oct14 19:13

26Aug13 23:48
26Aug13 5:04

26Aug13 0:09

Always prefer literals ...

Florian Rappl

25Aug13 20:26

question 20's answer is not correct, or not up to date

David Rogers Dev

25Aug13 17:06

Re: question 20's answer is not correct, or not up to date

Vikasahlawat24

Re: question 20's answer is not correct, or not up to date

http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers

25Aug13 18:14
26Aug13 1:04

6/7

11/21/2014

LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject
Ali Al OmairiAbu
AlHassan

Re: question 20's answer is not correct, or not up to date

David Rogers Dev

26Aug13 1:43

Re: question 20's answer is not correct, or not up to date

jsc42

27Aug13 7:11

Last Visit: 31Dec99 19:00

General

News

Last Update: 21Nov14 0:35

Suggestion

Question

Refresh

Bug

Answer

Joke

Rant

1 2 Next

Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411019.1 | Last Updated 3 Apr 2014

Select Language

Layout: fixed | fluid

http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers

Article Copyright 2013 by Vikas ahlawat www.tutoriz.com


Everything else Copyright CodeProject, 19992014

7/7