Professional Documents
Culture Documents
LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject
home
articles
quick answers
discussions
Sign in
features
community
help
Searchforarticles,questions,tips
CPOL
Rate this:
4.64 55 votes
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....
<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>
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.*/
varstatus=document.getElementById('checkbox1').checked;
alert(status);
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";
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>");
true
true
false
varx=Math.PI;//ReturnsPI
vary=Math.sqrt(16);//Returnsthesquarerootof16
varz=Math.sin(90);Returnsthesineof90
varobj={outerWidth:20};
functionsay(){
alert(this.outerWidth);
}
say();//willalertwindow.outerWidth
say.apply(obj);//willalertobj.outerWidth
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;
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
Research
Comments 28
console.log(myString.constructor,myStringLiteral.constructor);
Code
26 Consider the following statements and tell what would be the output of the logs statements?
Ans:
CodeProject
interviews Anders
console.log(price1===price2);//Logstrue.
Hejlsberg andconsole.log(price1===price3);/*Logsfalsebecauseprice3
Steve
Lucco, Microsoft
containsacomplexnumberobjectandprice1
Technical Fellows
isaprimitivevalue.*/
http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers
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);
varmyArray=[[[]]];
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
vars='5';
vara=s*1;
varb=+s;
typeof(s);//"string"
typeof(a);//"number"
typeof(b);//"number"
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
Spacing Relaxed
Noise Medium
Layout Normal
Go
Per page 25
Update
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
rvasif
3Apr14 6:41
gwag
3Apr14 1:40
My vote of 1
Member 10394796
2Apr14 8:15
Nice job
chait301
4Mar14 4:02
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
Florian Rappl
25Aug13 20:35
Vikasahlawat24
25Aug13 21:12
Florian Rappl
3Nov14 4:18
17Oct14 19:13
26Aug13 23:48
26Aug13 5:04
26Aug13 0:09
Florian Rappl
25Aug13 20:26
25Aug13 17:06
Vikasahlawat24
http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers
25Aug13 18:14
26Aug13 1:04
6/7
11/21/2014
LatestJavaScriptInterviewQuestionsandAnswersPDFCodeProject
Ali Al OmairiAbu
AlHassan
26Aug13 1:43
jsc42
27Aug13 7:11
General
News
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
http://www.codeproject.com/Articles/620811/LatestJavaScriptInterviewQuestionsandAnswers
7/7