New Advanced JavaScript Interview Questions for 2021

What is JavaScript?

What do you need to develop JavaScript? The answer is simple – any web browser such as Internet Explorer, Chrome, or Firefox.

JavaScript Interview Questions

Most browsers come up with developer tools that allow us to,

  • View the page that is rendered on the browser
  • View the HTML and JavaScript code
  • Debug JavaScript code
  • View console tab to take input commands.

Console is a simple text interface to input commands and view output. You can access the console by navigating to Developer Tools menu from the browser options. This comes handy for debugging.

Simply say console.log(“Hello World”); and try it out.

Creating new HTML elements using HTML DOM
You can create HTML elements using Javascript. Consider the following HTML code

Some text


Now you need to create a

tag inside using Javascript. How can you do that? Take a look at the following code snippet.

var myParagraph = document.createElement("p"); // Create a
element
var myText = document.createTextNode("text added using JS");
// Create a text node that has the text for

myParagraph.appendChild(myText); // Append the text to


document.body.appendChild(myParagraph); // Append

to

You can see that Javascript makes use of three methods i.e. createElement(), createTextNode(), and appendChild() to create a HTML element and append them in your HTML.

JavaScript Syntax

  • JavaScript is an interpreted language and requires no compilation.
  • JavaScript is case sensitive and constitutes statements.
  • The semicolon is the best way to separate the statements.
  • JavaScript is insensitive to whitespace.
  • Script tags holding JavaScript code are best placed at the end of the code.
  • Comments start with // or /* and */

Primitive JavaScript data types:

  • String [ “Howdy”]
  • Number [ 23, 482.038]
  • Boolean [ true, false ]
  • Null [ null value ]
  • Undefined [ value not defined ]
  • Objects

Numbers in JavaScript

Numbers are only double precision 64-bit values. There are no integers in JS. For example – 42 or 42.39794
Strings are to store characters.
Booleans are true and false.
Undefined is unique to JavaScript. It is a data type assigned to variables that are declared as variables but not assigned any values.
Null is a type to denote null value.

Variables in JavaScript

Variables are the identifiers to store data values in our code.
var is the keyword to declare a variable.
‘=’ is the operator to assign a value to a variable.
A variable must start with _ or $ or letter. 99temp is invalid whereas _99temp is valid.
In ES2015(known as ECMAscript), two other ways to declare variables were introduced- let and const. We can use these 2 keywords to define variables(now recommended).

Operators in JavaScript

Assignment Operators

  • Like most programming languages, = is the assignment operator
  • Variables can be declared either by key var and value OR simply by assigning values directly. Ex – var x = 42; OR x = 42 ;
  • Explicit type declaration is not necessary.
  • Same variable can be assigned values of different data types. To know the type of a variable, use typeof operator. Ex –
  • var x = “hello”; var x = true;
  • console.log(typeof x); //returns Boolean

Comparison Operators

  • JavaScript has operators like <, >, !=, >=, <= to compare 2 operands.
  • What is unique about JavaScript is the == and === operators?
  • == compares the operands and returns true without considering their data type. Ex: var a = 10, b= “10”;
  • if(a==b) results in true due to the same value they carry, but ignores data types differentiation.
  • However, if(a===b) results in false as they are of different data types.

Standard Arithmetic Operators

  • Addition + Ex: [5 + 8]
  • Subtraction – Ex: [49 – 38]
  • Division / Ex: [ 49 / 7]
  • Multiplication * Ex: [28 * 2]
  • Modulus % to return the remainder of a division – Ex: 50 % 7 is 1
  • Increment ++ to increment the operand itself by 1 – Ex: If x=4, x++ evaluates to 5
  • Decrement — to decrement the operand itself by 1 – Ex: if x= 10, x—- evaluates to 9

Logical Operators

  • AND &&, OR ||, NOT ! are the logical operators often used during conditional statements to test logic between variables.
  • Expr1 && Expr2 returns true if both are true, else returns false.
    Expr1 || Expr2 returns true if either is true.
    !Expr1 operates on single operand to convert true to false and vice versa.

String Operator

  • Operator + is used to concatenate strings. x = “Hello”; y = ” World “; x + y; /* Returns “Hello World” */
  • While concatenating, JavaScript treats all data types as strings even if values are of different data types.

x = “Hello”;
y = 100;
z = 333;
x + y + z; /* Returns “Hello100333” */

Conditions – If, Else, Else If in JavaScript
Syntax:
if (condition 1)
{ Execute code if condition 1 is true
}
else if (condition 2)
{ Execute code if condition 2 is true
}
else
{ Execute code if both conditions are false
}

Conditions – Switch in JavaScript
Syntax:
switch(expression)
{
case 1:
code to execute
break;
case 2:
code to execute
break;
case 3:
code to execute
break;
default:
code to execute }

Loops in JavaScript
Loops provide a quick and effortless way to repeat certain operations. Let us see some of the important loops in JS

for statement
while statement
do…while statement

For Loop
Syntax
for ([initialization]; [condition]; [final-expression])
statement
Initialization – An expression to initialize counter variable
condition – An expression to evaluate every loop iteration
final-expression – An expression to update the counter variable
Ex:

for (var i = 0; i < 9; i++) 
{
        console.log(i);
        // more statements
}

While Loop
Syntax
while (condition) { statement}

Ex:

var n = 0;
var x = 0;
while (n < 3) {
     n++;
     x += n;

}

Do… While Loop
Syntax
do statement while condition

var i = 0;
do {
i += 1;
console.log(i);
} while (i<5);

Functions in JavaScript
Like most programming languages, function is a piece of code that can be isolated to be called multiple times. Example of a function:

function Hello (string){
return “Hello” + ” ” + string
}
Hello(“Tom”)

Function as value
Functions are values in JavaScript. A function can be assigned as a value to a variable.

var f = function foo()
{
    console.log("Hello");
};
f();  /*  returns "Hello" */

Function as argument
A function can be passed as an argument to another function.

var f = function()
{ console.log(“Hello”);
};
var executor = function(fn)
{ fn();
}
executor(f); /* returns “Hello” */

Function as property
Functions can be added as a property to an object.

var myObj = {
“testProp” : true
};
myObj.prop1 = function() {
console.log (“Function in object”);
};
myObj.prop1();

Function arguments
A function can accept a varied number of arguments. i.e., a function “add” can be called by passing a different number of arguments different times. This is possible using an implicit argument by JavaScript called arguments.

var add = function()
{ var i, sum = 0;
for (i=0; i< arguments.length; i++)
{ sum += arguments[i];
}
return sum;
};

console.log(add(1,2,3,4,5)); /* 5 arguments/ console.log(add(1,2,3,4)); / 4 arguments*/

DOM Manipulation

The HTML DOM is an accepted guideline for how to access, update, add or remove HTML elements.
A Structure representation of an HTML document is provided by DOM.
An HTML document is completely built using objects. DOM represents it in an objected-oriented way which can be manipulated using scripting languages like javascript.
All the objects in the HTML document are hierarchically connected to one another. The document object forms the root of all objects.
There are three kinds of objects:

Core object (aray,math,etc)
User defined object(myobject,student,employee,etc)
Host object(h1,document,p,etc)

JAVAScript and AJAX

XHR Request
XMLHttpRequest is an object that is used by all modern browsers to communicate with the server.
This object is commonly used in AJAX programming.
You can also update only a part of a web page using this object.
It helps in making synchronous and asynchronous calls to the server and retrieving data without a full page reload.
Let us see how to make synchronous calls and its disadvantages
Example

var request= new XMLHttpRequest();
request.open(‘GET’,’Example.txt’,false);
request.send();
if(request.readyState == 4 && request.status == 200){
console.log(request);
document.writeln(request.responseText);
}
document.writeln(“some text”);
In this code, since we passed false as a parameter to open() function the browser treats this as synchronous calls and wait for the server to respond and then execute the next line.

Updating the DOM in JavaScript


By using the response from the server, you can update the DOM. One way of doing that is by using getElementById. Consider the same example from the previous card


Here the javascript will find the element with the required id and replace it with the response from the server. This can also be done using getElementByTagName which you should be familiar with previous topics.

Reading JSON Files using JavaScript


Now let us see how to read from a JSON file using AJAX. JSON consist of text, it can be converted into javascript object using JSON.parse() method

var request= new XMLHttpRequest();
request.open(‘GET’,’example.json’,true);
request.send();
request.onreadystatechange = function() {
if(request.readyState == 4 && request.status == 200){
var item= JSON.parse(request.responseText)
}
};
Here the variable item has a array of javascript objects where each object has a key value pair from the JSON file. Now you can loop through these object to read the data and use it to update DOM.

var list = '<ul>';
for(var i in item)
{
list += '<li>'+item[i].name+'</li>';
}

JavaScript Multiple Choice Questions of 2021

JavaScript Interview Questions

1) You wish to create an alert. Select the correct one from the following options.

a) alert(“goodbye’);

b) alert(‘he said “goodbye” ‘);

c) alert(‘goodbye”);

Answer: b) alert(‘he said “goodbye” ‘);

2) What is right about variables?

a) % is a valid first character for variable name

b) 7Wonders is a valid variable name to give

c) Variables are case sensitive

d) ^US is a valid variable name

Answer: c) Variables are case sensitive

(3)_ is a pretest loop that will execute until the value of z equals 10
a) while (z >10) { z–; }
b) do { ++z; } while (z < 10); c) for (var z= 1; z < 10; z++) { alert (z); } Answer : while (z >10) { z–; }

(4)__ allows you to loop through a block of code as long as the specified condition is true.
a) Tag
b) While
c) For
Answer : b) While

(5)Is the given assignment a valid variable assignment? var product cost = 3.45;

a) No, there should be no space in the variable name.

b) No, floating numbers are not allowed.

c) Yes, it is valid.

Answer: a) No, there should be no space in the variable name.

(6)JavaScript has to be called inside __ tags.

a) body

b) script

c) head

d) Either in body or head

Answer: b) script

(7) What is the value of C here?

var a = 100; var b = “10”; var c = a + b;

a) None

b) 10100

c) 110

d) 10010

Answer: d) 10010

(8) Using HTML button tag, JavaScript command can be executed by using __ function.

a) “alert(Button1);”

b) “alert(‘Button1’); —

c) “alert(‘Button”);”

d) “alert(‘Button1’);”

Answer: b) “alert(‘Button1’);

(9) Document object is part of __ object.

a) Tree

b) System

c) Window

Answer: c) Window

(10) Which statement about the name and id attributes of form fields is false?

a) Either attribute may be omitted if it is unused.

b) The name attribute can be used to access the field using getElementsByName().

c) It is customary to give form fields both attributes, with the same value if possible.

d) The id attribute is what is sent when the form is submitted)

Answer: d) The id attribute is what is sent when the form is submitted.

(11) Document object is part of __ object

a) Tree

b) Window

c) System

Answer: b) Window

(12) Your div element in a document has id=”answers”. If a JS fn sets d=document.getElementById(“answers”), then which is the preferred way to add a paragraph containing the word “Hello” as a child of that div?

a) d.appendChild(“Hello “);

b) answers.innerHTML = “Hello”;

c) d.innerHTML = “Hello “;

d) p = createElement(“p”); p.innerHTML = “Hello”; d.appendChild(p);

Answer: d) p = createElement(“p”); p.innerHTML = “Hello”; d.appendChild(p);

(13)Is the following a valid variable definition? var 100apples
a) No
b) Yes
Answer : a) No

(14)You want to create an alert. Select the correct one
a) alert(‘goodbye”);
b) alert(‘he said “goodbye” ‘);
c) alert(“goodbye’);
Answer : b) alert(‘he said “goodbye” ‘);

(15)JavaScript has to called inside __ tags
a) Either in body or head
b) head
c) body
d) script
Answer : d) script

(16)Is the following a valid variable assignment var product cost = 3.45;
a) No. There should be no space in the variable name
b) No. Floating numbers are not allowed
c) Yes. It is valid
Answer : a) No. There should be no space in the variable name

(17) Suppose we have a text “human” that we want to convert into string without using the “new” operator. Which is the correct way from the following to do so:

a) toString()
b) String(human)
c) String newvariable=”human”
d) Both human.toString() and String(human)

(18)What is true about variables
a) 7Wonders is a valid variable name to give
b) % is a valid first character for variable name
c) Variables are case sensitive
d) ^US is a valid variable name
Answer : c) Variables are case sensitive

(19)Select the statement that has correct JavaScript syntax
a) document.write(“text”)
b) alert stop ;
c) console.log(“text”);
Answer : c) console.log(“text”);

(21) The syntax of Eval is ____
a) [objectName.]eval(numeriC.
b) [objectName.]eval(string)
c) [EvalName.]eval(string)
d) [EvalName.]eval(numeriC.
Answer : b) [objectName.]eval(string)

(22)To display whether a value is a number or not, __ is used
a) isNan
b) NaN
c) undefined
d) isundefined
Answer : isNan

(23)isNan function returns _ if the argument is not a number otherwise it is _
a) False/True
b) False/False
c) True / False
d) True / True
Answer : True / False

(24)Code A: var x = 10; y = –x + 1;
alert(y);
Code B: var x = 10;
y = x– + 1;
alert(y);
What is the output for code A and B?
a) 10,11
b) 10,10
c) 11,10
d) 11,11
Answer : 10,11

(25)Which statement will return the value false?
a) var result = 20 < 50; b) var result = 30 >= 30;
c) var result = (20 === “20”) && (50 < 30);
Answer : var result = (20 === “20”) && (50 < 30);

(26) Find out the correct output of the following given piece of code from the given options:

functionfun()
{
int y=10;
char z=10;
if(y.tostring()===z)
returntrue;
else
returnfalse;
}
a) logical error
b) false
c) runtime error
d) true

III. This set of questions focuses on operators and expressions of JavaScript
(27) See the given code of JavaScript and choose the correct output from the following:

var string1 = “40”;
varvalueinit=50;
alert( string1 +intvalue);
a) 4090
b) 90
c) 4050
d) Exception

(28)What is the value of C? var a = 100; var b = “10”; var c = a + b;
a) 10010
b) 110
c) None
d) 10100
Answer : 10010

(29)__ is used to exit a loop early.
a) Break
b) Alert
c) Exit
d) Continue
Answer : Break

(30) When a user views a page containing a JavaScript program, which machine actually executes the script?
a) The User’s machine running a Web browser
b) The Web server
c) A central machine deep within Netscape’s corporate offices
d) None of the above
Answer : a) The User’s machine running a Web browser

(31)Can arrays in JavaScript be extended?
a) Yes, they can be
b) No, they cannot be
c) May be, they can be extended conditionally
Answer : Yes, they can be

(32)In multidimensional array mySubject, which of the following will allow assigning the value 100 in position 5 of the third

mySubject array?
a) mySubject[3][4] = 100
b) mySubject[5][3] = 100
c) mySubject[4][2] = 100
d) mySubject[2][4] = 100
e) mySubject[3][5] = 100
Answer : mySubject[2][4] = 100

(33)Which is the correct way to create an array in JavaScript? I) var myProg = []; II) var myArray = [“C”,”Java”,”C++”,”Python”];

III) var myProg = new Array();
a) I, III
b) II, III
c) I, II
d) I, II & III
Answer : I, II & III

(34)What is true about array
a) Can have combination of data types in a single array list
b) Must have same data types for array list
Answer : Can have combination of data types in a single array list

(35)FIbonacci Series Program
function fibonacciSequence(input)
{
var a=0;b=1;c=0;
var array1=[0,1];
for(var i=2;i<=input;i++)
{
c=a+b;
a=b;
b=c;
array1.push(c)
}
return array1;
}
a) Above code is true —
b) Above code is incorrect
Answer : True

(36) What is true about functions : I) Functions are objects II) Can be assigned to a variable III) Can be anonymous IV) Return value

type has to be defined in function declaration
a) I, II
b) I, II, III
c) I, II, III, IV
d) I, II, IV
Answer : I, II, III

(37)Object’s properties are similar to variables and methods are similar to
a) Conditionals
b) Properties
c) Functions
d) Operators
Answer : Functions

(38)What is the output for the following
function test(x) {
while(x < 5)
{ x++; }
return x; }
alert(test(2));
a) 6
b) 3
c) 2
d) 5
Answer : d) 5

(39)_ is an function contained within an object
a) Object
b) None of the options
c) Function
d) Method
Answer : d) Method

(40)Which of the following regarding scope is true?
a) Variables that have a local scope are only visible in the function in which they are declared
b) Function parameters are visible in the function in which they are used
c) Data that is stored in a variable when a function is called is never cleared out
d) All variables you use in your program have to be declared as global variables
Answer : Variables that have a local scope are only visible in the function in which they are declared

(41)Function in JavaScript is an object. True or False ?
a) False
b) True
Answer : b) True

(42)Anonymous functions can be created in JavaScript. What do anonymous function do?
a) Overwrite variables that are to be kept updated
b) Process a variable before passing it on to another function
c) Automatically define the scope of a value inside a parameter
Answer : Process a variable before passing it on to another function

(43)What is the output of the following expression?
function multi(x,y) {
var c = x*y;
}
multi(20,3);
a) 20
b) 60
c) 3
d) Nothing
Answer : d) Nothing

(44)var i = 1; if (function f(){}) { i += typeof f; } x;
a) 1
b) undefined
c) Nan
d) Error
Answer : b) undefined

(45)What is the output for the following code
(function f(){
function f(){
return 1; }
return f();
function f()
{ return 2; } })();
a) NaN
b) 1
c) 2
d) Error
Answer : c) 2

(46)Which statement about the name and id attributes of form fields is false?
a) It is customary to give form fields both attributes, with the same value if possible.
b) The id attribute is what is sent when the form is submitted.
c) The name attribute can be used to access the field using getElementsByName().
d) Either attribute may be omitted if it is unused.
Answer : b) The id attribute is what is sent when the form is submitted.

(47)Document object is part of __ object
a) System
b) Tree
c) Window
Answer : c) Window

(48)Using HTML button tag, JavaScript command can be executed by using __ function
a) “alert(‘Button1’);
b) “alert(Button1);”
c) “alert(‘Button1’);”
d) “alert(‘Button”);”
Answer : “alert(‘Button1’);

(49)By modifying the DOM, the contents on the page also gets modified
a) True
b) False
Answer : a) True

(50)For any structured document, _ defines a standard set of objects
a) XML DOM
b) HTML DOM
c) Core DOM
Answer : c) Core DOM

(51)Which statement accesses HTML classes?
a) getElementsByClassName
b) class.name
c) getElementById
Answer : a) getElementsByClassName

(52)How many ‘onload’ events can be written in a page
a) 2
b) 1
c) None
d) Many
Answer : b) 1

(53)Multiple variables can be created and initialized in a single JavaScript statement.

a) True
b) False

Answer : a) True

(54)Which statement will return the value false?

a) var result = (20 === “20”) && (50 < 30);

b) var result = 30 >= 30;

c) var result = 20 < 50;

Answer : a) var result = (20 === “20”) && (50 < 30);

(55)Which is the most preferred way of handling events?
a) Referencing an element with the event and assign a function as a value
b) Register a listener to an element
c) Writing the JavaScript as an attribute to an element
Answer : b) Register a listener to an element

(56)AJAX requests can support data transfer in __ format
a) None of the options
b) JSON
c) XML
d) Any
Answer : d) Any

(57)_ object is used to make calls and request data from server
a) GET
b) XML
c) XMLHttpRequest
Answer : c) XMLHttpRequest

(58)The data from the AJAX request is usually in XML. True or False?
a) False
b) True
Answer : a) False

(59)What is the output you get for the following code?
(function()
{
return typeof arguments; })
();
a) undefined
b) array
c) arguments
d) object
Answer : d) object

(60) Why so JavaScript and Java have similar name?
a) JavaScript is a stripped-down version of Java
b) JavaScript’s syntax is loosely based on Java’s
c) They both originated on the island of Java
d) None of the above
Answer : b) JavaScript’s syntax is loosely based on Java’s

(61) Which of the following is the correct output for the following JavaScript code:

Int x=8;
if(x>9)
{
document.write(9);
}
else
{
document.write(x);
}
a) 9
b) 0
c) 8
d) Undefined

(62) Which of the following is the correct output for the following JavaScript code:

var grade=’C’;
var result;
switch(grade)
{
case’A’:
{
result+=”10″;
break;
}
case’B’:
{
result+=” 9″;
break;
}
case’C’:
{
result+=” 8″;
break;
}
default:
result+=” 0″;
}
document.write(result);
a) 10
b) 9
c) 8
d) 0

(63) __ JavaScript is also called client-side JavaScript.
a) Microsoft
b) Navigator
c) LiveWire
d) Native
Answer : b) Navigator

(64) __ JavaScript is also called server-side JavaScript.
a) Microsoft
b) Navigator
c) LiveWire
d) Native
Answer : c) LiveWire

(65) What are variables used for in JavaScript Programs?
a) Storing numbers, dates, or other values
b) Varying randomly
c) Causing high-school algebra flashbacks
d) None of the above
Answer : a) Storing numbers, dates, or other values

(66) _ JavaScript statements embedded in an HTML page can respond to user events such as mouse-clicks, form input, and page navigation.
a) Client-side
b) Server-side
c) Local
d) Native
Answer : a) Client-side

(67) What should appear at the very end of your JavaScript?
The
b) The

(68) Which of the following can’t be done with client-side JavaScript?
a) Validating a form
b) Sending a form’s contents by email
c) Storing the form’s contents to a database file on the server
d) None of the above
Answer : c) Storing the form’s contents to a database file on the server

(69) Which of the following are capabilities of functions in JavaScript?
a) Return a value
b) Accept parameters and Return a value
c) Accept parameters
d) None of the above
Answer : c) Accept parameters

(70) Which of the following is not a valid JavaScript variable name?
a) 2names
b) _first_and_last_names
c) FirstAndLast
d) None of the above
Answer : a) 2names

(71) __ tag is an extension to HTML that can enclose any number of JavaScript statements.
a) <br /> b)  <BODY><br /> c) <HEAD><br /> d) <TITLE><br /> Answer : a) <SCRIPT></p>


(72) How does JavaScript store dates in a date object?
a) The number of milliseconds since January 1st, 1970
b) The number of days since January 1st, 1900
c) The number of seconds since Netscape’s public stock offering.
d) None of the above
Answer : a) The number of milliseconds since January 1st, 1970

(73)Multiple variables can be created and initialized in a single JavaScript statement
a) False
b) True
Answer : b) True

(74)Which of the following are not valid in JavaScript?
a) “My name is “Harry” “
b) “My name is Harry”
c) My name is Harry’
d) “My name is ‘Harry’ “
Answer : a) “My name is “Harry” “

(75) Which of the following attribute can hold the JavaScript version?
a) LANGUAGE
b) SCRIPT
c) VERSION
d) None of the above
Answer : a) LANGUAGE

(76) What is the correct JavaScript syntax to write “Hello World”?
a) System.out.println(“Hello World”)
b) println (“Hello World”)
c) document.write(“Hello World”)
d) response.write(“Hello World”)
Answer : c) document.write(“Hello World”)

(77)  Which of the following way can be used to indicate the LANGUAGE attribute?
a) <LANGUAGE="JavaScriptVersion">
b)  <SCRIPT LANGUAGE="JavaScriptVersion">
c) <SCRIPT LANGUAGE="JavaScriptVersion">    JavaScript statements…</SCRIPT>
d) <SCRIPT LANGUAGE="JavaScriptVersion"!>    JavaScript statements…</SCRIPT>
Answer : c) <SCRIPT LANGUAGE="JavaScriptVersion">    JavaScript statements…</SCRIPT>

(78)  Inside which HTML element do we put the JavaScript?
a) <js>
b)  <scripting>
c) <script>
d) <javascript>
Answer : c) <script>

(79) Which of the following option is used as hexadecimal literal beginning?

a) 00
b) 0x
c) 0X
d) Both 0x and 0X

(80) When there is an indefinite or an infinite value during an arithmetic computation in a program, then JavaScript prints______.

a) Prints an exception error
b) Prints an overflow error
c) Displays “Infinity”
d) Prints the value as such

(81)  What is the correct syntax for referring to an external script called " abc.js"?
a) <script href=" abc.js">
b)  <script name=" abc.js">
c) <script src=" abc.js">
d) None of the above
Answer : c) <script src=" abc.js">

(82) Which types of image maps can be used with JavaScript?
a) Server-side image maps
b) Client-side image maps
c) Server-side image maps and Client-side image maps
d) None of the above
Answer : b) Client-side image maps

(83) Which of the following navigator object properties is the same in both Netscape and IE?
a) navigator.appCodeName
b) navigator.appName
c) navigator.appVersion
d) None of the above
Answer : a) navigator.appCodeName

(84) Which is the correct way to write a JavaScript array?
a) var txt = new Array(1:”tim”,2:”kim”,3:”jim”)
b) var txt = new Array:1=(“tim”)2=(“kim”)3=(“jim”)
c) var txt = new Array(“tim”,”kim”,”jim”)
d) var txt = new Array=”tim”,”kim”,”jim”
Answer : c) var txt = new Array(“tim”,”kim”,”jim”)

(85) What does the

(86) If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph?
a) “New Text”?
b) para1.value=”New Text”;
c) para1.firstChild.nodeValue= “New Text”;
d) para1.nodeValue=”New Text”;
Answer : b) para1.value=”New Text”;

(87) JavaScript entities start with and end with __.
a) Semicolon, colon
b) Semicolon, Ampersand
c) Ampersand, colon
d) Ampersand, semicolon
Answer : d) Ampersand, semicolon

(88) Which of the following best describes JavaScript?
a) a low-level programming language.
b) a scripting language precompiled in the browser.
c) a compiled scripting language.
d) an object-oriented scripting language.
Answer : d) an object-oriented scripting language.

(89) Choose the server-side JavaScript object?
a) FileUpLoad
b) Function
c) File
d) Date
Answer : c) File

(90) Choose the client-side JavaScript object?
a) Database
b) Cursor
c) Client
d) FileUpLoad
Answer : d) FileUpLoad

(91) Which of the following is not considered a JavaScript operator?
a) new
b) this
c) delete
d) typeof
Answer : b) this

(92) ______method evaluates a string of JavaScript code in the context of the specified object.
a) Eval
b) ParseInt
c) ParseFloat
d) Efloat
Answer : a) Eval

(93) JavaScript is interpreted by _
a) Client
b) Server
c) Object
d) None of the above
Answer : a) Client

(94) Using _ statement is how you test for a specific condition.
a) Select
b) If
c) Switch
d) For
Answer : b) If

(95) Which of the following is the structure of an if statement?
a) if (conditional expression is true) thenexecute this codeend if
b) if (conditional expression is true)execute this codeend if
c) if (conditional expression is true) {then execute this code>->}
d) if (conditional expression is true) then {execute this code}
Answer : c) if (conditional expression is true) {then execute this code>->}

(96) How to create a Date object in JavaScript?
a) dateObjectName = new Date([parameters])
b) dateObjectName.new Date([parameters])
c) dateObjectName := new Date([parameters])
d) dateObjectName Date([parameters])
Answer : a) dateObjectName = new Date([parameters])

(97) The _ method of an Array object adds and/or removes elements from an array.
a) Reverse
b) Shift
c) Slice
d) Splice
Answer : d) Splice

(98) To set up the window to capture all Click events, we use which of the following statement?
a) window.captureEvents(Event.CLICK);
b) window.handleEvents (Event.CLICK);
c) window.routeEvents(Event.CLICK );
d) window.raiseEvents(Event.CLICK );
Answer : a) window.captureEvents(Event.CLICK);

(99)  Which tag(s) can handle mouse events in Netscape?
a) <IMG>
b) <A>
c) <BR>
d) None of the above
Answer : b) <A>

(100)Which one of the following options are not valid in JavaScript?

a) “My name is “Harry” ” —

b) “My name is ‘Harry’ “

c) “My name is Harry”

d) My name is Harry’

(101)Code A: var x = 10; y = –x + 1;
alert(y);
Code B: var x = 10;
y = x– + 1;
alert(y);
What is the output for code A and B?

a) 10,10

b) 10,11 —

c) 11,11

d) 11,10

(102) __ is the tainted property of a window object.
a) Pathname
b) Protocol
c) Defaultstatus
d) Host
Answer : c) Defaultstatus

(103) To enable data tainting, the end user sets the _ environment variable.
a) ENABLE_TAINT
b) MS_ENABLE_TAINT
c) NS_ENABLE_TAINT
d) ENABLE_TAINT_NS
Answer : c) NS_ENABLE_TAINT

(104) In JavaScript, _ is an object of the target language data type that encloses an object of the source language.
a) a wrapper
b) a link
c) a cursor
d) a form
Answer : a) a wrapper

(105) When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type _
a) ScriptObject
b) JSObject
c) JavaObject
d) Jobject
Answer : b) JSObject

(106)function multi(a,b) { var ans = a * b; return ans; } var c = _
a) multi(15,2);
b) multi 15, 2;
c) multi();
Answer : multi(15,2);

(107)What is the output you get for the following code?
(function()
{
return typeof arguments; })
();
a) arguments
b) array
c) object
d) undefined
Answer : object

(108)In JavaScript, object is a container of properties and functions. Properties are identified by __ and behavior is identified by


a) variables, functions
b) attributes, functions
c) attributes, variables
d) functions, variables
Answer : variables, functions

(109)To retrieve the day of the month from the Date object, which is the code to select?
var date_obj = new Date(2016,1,1);
a) month_date = date_obj.toDateString();
b) month_day = date_obj.getDay();
c) month_date = date_obj.getMonth();
d) var month_day = date_obj.getDate();
Answer : var month_day = date_obj.getDate();

(110) _ class provides an interface for invoking JavaScript methods and examining JavaScript properties.
a) ScriptObject
b) JSObject
c) JavaObject
d) Jobject
Answer : b) JSObject

(111) _ is a wrapped Java array, accessed from within JavaScript code.
a) JavaArray
b) JavaClass
c) JavaObject
d) JavaPackage
Answer : a) JavaArray

(112) A __ object is a reference to one of the classes in a Java package, such as netscape.javascript .
a) JavaArray
b) JavaClass
c) JavaObject
d) JavaPackage
Answer : b) JavaClass

(113) The JavaScript exception is available to the Java code as an instance of __
a) netscape.javascript.JSObject
b) netscape.javascript.JSException
c) netscape.plugin.JSException
d) None of the above
Answer : b) netscape.javascript.JSException

(114) To automatically open the console when a JavaScript error occurs which of the following is added to prefs.js?
a) user_pref(” javascript.console.open_on_error”, false);
b) user_pref(“javascript.console.open_error “, true);
c) user_pref(“javascript.console.open_error “, false);
d) user_pref(“javascript.console.open_on_error”, true);
Answer : d) user_pref(“javascript.console.open_on_error”, true);

(115) The syntax of a blur method in a button object is __
a) Blur()
b) Blur(contrast)
c) Blur(value)
d) Blur(depth)
Answer : a) Blur()

(116) The syntax of capture events method for document object is __
a) captureEvents()
b) captureEvents(args eventType)
c) captureEvents(eventType)
d) captureEvents(eventVal)
Answer : c) captureEvents(eventType)

(117) The syntax of close method for document object is __
a) Close(doC.
b) Close(object)
c) Close(val)
d) Close()
Answer : d) Close()

(118)

Output——?
A. 44
B. 8
C. 4
D. Error output
Answer : A. 44

(119) Is it possible to nest functions in JavaScript?
A. True
B. False
Answer : A. True

(120) document.write(navigator.appCodeName);

A. get code name of the browser of a visitor
B. set code name of the browser of a visitor
C. None of the above
Answer : A. get code name of the browser of a visitor

(121) Scripting language are
A. High Level Programming language
B. Assembly Level programming language
C. Machine level programming language
Answer : A. High Level Programming language

(122) Which best explains getSelection()?
A. Returns the VALUE of a selected OPTION.
B. Returns document.URL of the window in focus.
C. Returns the value of cursor-selected text
D. Returns the VALUE of a checked radio input.
Answer : C. Returns the value of cursor-selected text

(123) Choose the client-side JavaScript object:
A. Database
B. Cursor
C. Client
D. FileUpLoad
Answer : D. FileUpLoad

(124) What is mean by “this” keyword in javascript?
A. It refers current object
B. It referes previous object
C. It is variable which contains value
D. None of the above
Answer : A. It refers current object

(125) In JavaScript, Window.prompt() method return true or false value ?
A. False
B. True
Answer : A. False

(126)
A. 258
B. Error
C. 7
D. 78
Answer : D. 78

(127)
A. 9123
B. 91234
C. 80000
D. None of the above
Answer : A. 9123

(128) Which type of JavaScript language is _

a) Object-Oriented
b) Object-Based
c) Assembly-language
d) High-level

(129) Which of the following is the correct output for the following JavaScript code:

varx=5,y=1
var obj ={ x:10}
with(obj)
{
alert(y)
}
a) 1
b) Error
c) 10
d) 5

(130) Which one of the following also known as Conditional Expression:

a) Alternative to if-else
b) Switch statement
c) If-then-else statement
d) immediate if

(131) Among the following given JavaScript snipped codes, which is more efficient:

Code A

for(var number=10;number>=1;number–)
{
document.writeln(number);
}
Code B

var number=10;
while(number>=1)
{
document.writeln(number);
number++;
}
a) Code 1
b) Code 2
c) Both Code 1 and Code 2
d) Cannot Compare

(132)In JavaScript, what is a block of statement?

a) Conditional block
b) block that combines a number of statements into a single compound statement
c) both conditional block and a single statement
d) block that contains a single statement

(133) When interpreter encounters an empty statements, what it will do:

a) Shows a warning
b) Prompts to complete the statement
c) Throws an error
d) Ignores the statements

(134) The “function” and ” var” are known as:

a) Keywords
b) Data types
c) Declaration statements
d) Prototypes

(135) In the following given syntax of the switch statement, the Expression is compared with the labels using which one of the following operators?

switch(expression)
{
statements
}
a) ===
b) equals
c) ==
d) equals

(136) What will happen, if the following JavaScript code is executed?

var count =0;
while (count <10)
{
console.log(count);
count++;
}
a) An error is displayed
b) An exception is thrown
c) The values of count variable are logged or stored in a particular location or storage
d) The value of count from 0 to 9 is displayed in the console

(137) Which of the following is the correct output for the following JavaScript code:

var grade=’D’;
var result;
switch(grade)
{
case’A’:
result+=”10″;
case’B’:
result+=” 9″;
case’C’:
result+=” 8″;
case ‘D’
result+=” 6″;
default:
result+=” 0″;
}
document.write(result);
a) 10
b) 6
c) 33
d) 0

(138) Which of the following is the correct output for the following JavaScript code:

var x=3;
var y=2;
var z=0;
If(x==y)
document.write(x);
elseif(x==y)
document.write(x);
else
document.write(z);
a) 3
b) 0
c) Error
d) 2

(139) To open a dialog box each time an error occurs, which of the following is added to prefs.js?
a) user_pref(“javascript.classic.error_alerts”, true);
b) user_pref(“javascript.classic.error_alerts “, false);
c) user_pref(“javascript.console.open_on_error “, true);
d) user_pref(“javascript.console.open_on_error “, false);
Answer : A

(140) Which of the following is the correct output for the following JavaScript code:

var grade=’Z’;
var result;
switch(grade)
{
case’A’:
result+=”10″;
case’B’:
result+=” 9″;
case’C’:
result+=” 8″;
default:
result+=” 0″;
}
document.write(result);
a) 10
b) 17
c) 18
d) 0

II. This set of questions focuses on the variables in JavaScript
(141) Which of the following variables takes precedence over the others if the names are the same?

a) Global variable
b) The local element
c) The two of the above
d) None of the above

(142) Which one of the following is the correct way for calling the JavaScript code?

a) Preprocessor
b) Triggering Event
c) RMI
d) Function/Method

(143) Which of the following type of a variable is volatile?

a) Mutable variable
b) Dynamic variable
c) Volatile variable
d) Immutable variable

(144) In the JavaScript, which one of the following is not considered as an error:

a) Syntax error
b) Missing of semicolons
c) Division by zero
d) Missing of Bracket

(145) Which of the following givenfunctions of the Number Object formats a number with a different number of digits to the right of the decimal?

a) toExponential()
b) toFixed()
c) toPrecision()
d) toLocaleString()

(146) Which of the following number object function returns the value of the number?

a) toString()
b) valueOf()
c) toLocaleString()
d) toPrecision()

(147) Which of the following function of the String object returns the character in the string starting at the specified position via the specified number of characters?

a) slice()
b) split()
c) substr()
d) search()

(148) In JavaScript the x===y statement implies that:

a) Both x and y are equal in value, type and reference address as well.
b) Both are x and y are equal in value only.
c) Both are equal in the value and data type.
d) Both are not same at all.

(149) Choose the correct snippet from the following to check if the variable “a” is not equal the “NULL”:

a) if(a!==null)
b) if (a!)
c) if(a!null)
d) if(a!=null)

(150)What option would you specify when inserting code in a web page? script type=”__
a) text/language
b) JavaScript/text
c) text/JavaScript
Answer : text/JavaScript

(151)What is the ideal place to load the external JavaScript file in your HTML document
a) Towards the beginning of the body to load the page along with the JavaScript code
b) Towards the end of the body to increase the performance of the webpage
c) Anywhere within the body is good enough
Answer : Towards the end of the body to increase the performance of the webpage

(152)__ is used to display whether a value is a number or not.

a) isNan

b) NaN

c) undefined

d) isundefined

Answer: a) isNan

(153) See the given code of JavaScript and choose the correct output from the following:

functioncomparing()
{
intx=9;
chary=9;
if(x==y)
returntrue;
else
returnfalse;
}
a) compilation error
b) false
c) runtime error
d) true

(154) What will be the output of the following JavaScript code?

functioncomparison()
{
int number=10;
if(number===”10″)
returntrue;
else
returnfalse;
}
a) True
b) false
c) runtime error
d) compilation error

Leave a Comment