Latest JavaScript Interview Questions and Answers PDF - CodeProject2019
Latest JavaScript Interview Questions and Answers PDF - CodeProject2019
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....
Code
Hide Copy Code
<head>
<title>Page Title</title>
<script language="JavaScript" type="text/javascript">
var name = "Vikas Ahlawta"
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
Hide Copy Code
<head>
<title>Page Title</title>
<script type="text/javascript" src="myjavascript.js"></script>
</head>
6) What are the boolean operators supported by JavaScript? And Operator: &&
Or Operator: ||
https://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers 1/7
8/22/2017 Latest JavaScript Interview Questions and Answers PDF - CodeProject
Not Operator: !
Code
Hide Copy Code
<!DOCTYPE html>
<html>
<body>
Full name: <input type="text" id="txtFullName"
There are following ways to access the value of the above textbox:
alert(name);
or:
document.forms[0].mybutton.
alert(name);
Note: This uses the "name" attribute of the element to locate it.
/*
*/ is used for block comments
ex:-
Hide Copy Code
10) How will you get the Checkbox status whether it is checked or not?
Ans:
Code
Hide Copy Code
https://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers 2/7
8/22/2017 Latest JavaScript Interview Questions and Answers PDF - CodeProject
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.
Code
Hide Copy Code
document.write(isNaN("Hello")+ "<br>");
document.write(isNaN("2013/06/23")+ "<br>");
document.write(isNaN(123)+ "<br>");
true
true
false
Code
Hide Copy Code
function say() {
alert(this.outerWidth);
}
19) How do you change the style/class on any element using JavaScript?
Ans:
Code
Hide Copy Code
document.getElementById("myText").style.fontSize = "10";
https://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers 3/7
8/22/2017 Latest JavaScript Interview Questions and Answers PDF - CodeProject
-or-
Hide Copy Code
document.getElementById("myText").className = "anyclass";
Code
Hide Copy Code
23) How you will add function as a property in a JavaScript object? Give an example.
Ans:
Code
Hide Copy Code
24) What is the similarity between the 1st and 2nd statement?
1st:- var myString = new String('male'); // An object.
2nd:- var myStringLiteral = 'male'; // Primitive string value, not an object.
Ans: Both will call String() constructor function
You can confirm it by running the following statement:
console.log(myString.constructor, myStringLiteral.constructor);
Code
Hide Copy Code
26) Consider the following statements and tell what would be the output of the logs statements?
Ans:
Hide Copy Code
console.log(price1 === price2); // Logs true.
console.log(price1 === price3); /* Logs false because price3
contains a complex number object and price 1
is a primitive value. */
https://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers 4/7
8/22/2017 Latest JavaScript Interview Questions and Answers PDF - CodeProject
27) What would be the output of the following statements?
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.
Code
Hide Copy Code
var object1 = { same: 'same' };
var object2 = object1;
console.log(object1 === object2);
30) Name any two JavaScript functions which are used to convert nonnumeric values into numbers?
Ans:
Code
Hide Copy Code
var n1 = Number("Hello world!"); //NaN
var n2 = Number(""); //0
var n3 = Number("000010"); //10
var n4 = Number(true); //1
var n5 = 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.
var s = '5';
var a = s*1;
var b = +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 TWITTER
https://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers 5/7
8/22/2017 Latest JavaScript Interview Questions and Answers PDF - CodeProject
ASP.NET MVC interview questions with answers Generate and add keyword variations using AdWords API
Latest jQuery interview questions and answers Window Tabs (WndTabs) Add-In for DevStudio
Search Comments Go
My vote of 4
Ujjval Shukla 10-Jul-15 22:01
Just my opinion
Dvid Kocsis 26-May-15 2:47
My vote of 4
Novakovi 3-Nov-14 3:18
Thanks
Girish Nama 17-Oct-14 18:13
My Vote 5
Shemeemsha RA 6-Oct-14 19:52
My vote of 5
Sibeesh KV 15-Sep-14 23:07
My vote of 1
Member 10394796 2-Apr-14 7:15
https://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers 6/7
8/22/2017 Latest JavaScript Interview Questions and Answers PDF - CodeProject
Nice job
chait301 4-Mar-14 3:02
Thanks
oddadmix 30-Sep-13 4:38
My vote of 3
DhruvSakalley 8-Sep-13 14:33
My vote of 4
Member 10004231 29-Aug-13 23:52
My vote of 5
teeoneone 27-Aug-13 23:32
My vote of 4
Nitij Kumar 27-Aug-13 1:26
My vote of 5
Juhi Paunikar 26-Aug-13 22:48
My vote of 5
Sk. Tajbir 26-Aug-13 4:04
My vote of 5
AlexCode 25-Aug-13 11:40
interesting, Thanks
Mayank2yk 25-Aug-13 11:20
My vote of 4
Sanjay K. Gupta 14-Jul-13 19:02
Refresh 1
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
https://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers 7/7