Javascript MCQ Number 01125

Javascript MCQ Set 1

1. Which syntax is used to describe elements in CSS?
a) Protectors
b) Selectors
c) Both Protectors and Selectors
d) None of the mentioned

Answer

Answer: b [Reason:] CSS stylesheets have a very powerful syntax, known as selectors, for describing elements or sets of elements within a document.

2. What does the following code snippet mean?

#log>span

a) Span child after log declaration
b) Specific span child of id greater than log
c) Span child less than log
d) Any span child of the element with id as log

Answer

Answer: d [Reason:] The above code snippet means that any span child of the element with id=”log”.

3. Which of the following is the ultiate element selection method?
a) querySelectorAll()
b) querySelector()
c) queryAll()
d) query()

Answer

Answer: a [Reason:] querySelectorAll() is the ultimate element selection method: it is a very powerful technique by which client-side JavaScript programs can select the document elements that they are going to manipulate.

4. Which of the following is the Web application equivalent to querySelectorAll()?
a) #()
b) &()
c) $()
d) None of the mentioned

Answer

Answer: c [Reason:] Web applications based on jQuery use a portable, cross-browser equivalent to querySelectorAll() named $().

5. The C in CSS stands for
a) Continuous
b) Cascaded
c) Contentional
d) Cascading

Answer

Answer: d [Reason:] The C in CSS stands for “cascading”. This term indicates that the style rules that apply to any given element in a document can come from a “cascade” of different sources.

6. The latest version of CSS is
a) CSS1
b) CSS2
c) CSS3
d) CSS4

Answer

Answer: c [Reason:] The latest version of CSS is CSS3.

7. Which of the following is an example of a Shortcut Property?
a) border
b) font
c) text
d) all of the mentioned

Answer

Answer: d [Reason:] All of the above mentioned properties are shortcut properties. For example, the font-family, font-size, font-style, and font-weight properties can all be set at once using a single font property with a compound value:

font: bold italic 24pt helvetica;

8. Which of the following is the default positioning elements with CSS?
a) relative
b) static
c) absolute
d) none of the mentioned

Answer

Answer: b [Reason:] static is the default value and specifies that the element is positioned according to the normal flow of document content (for most Western languages, this is left to right and top to bottom).

9. Which property lays the element according to the normal flow?
a) relative
b) absolute
c) fixed
d) static

Answer

Answer: a [Reason:] When the position property is set to relative, an element is laid out according to the normal flow, and its position is then adjusted relative to its position in the normal flow.

10. Which of the following property allows you to specify an element’s position with respect to the browser window?
a) relative
b) fixed
c) static
d) absolute

Answer

Answer: b [Reason:] The fixed value allows you to specify an element’s position with respect to the browser window. Elements with fixed positioning are always visible and do not scroll with the rest of the document. Like absolutely positioned elements, fixed-position elements are independent of all others and are not part of the document flow.

Javascript MCQ Set 2

1. The central object in a larger API is known as
a) Document Object Material
b) Document Object Model
c) Binary Object Model
d) None of the mentioned

Answer

Answer: b [Reason:] The Document object does not stand alone, however. It is the central object in a larger API, known as the Document Object Model, or DOM, for representing and manipulating document content.

2. The paragraph “p” is a part of
a) h1
b) body
c) html
d) Both body and html

Answer

Answer: d [Reason:] The paragraph tag belongs to both html and body tags.

3. The node directly above a node is called
a) sibling
b) child
c) parent
d) ancestors

Answer

Answer: c [Reason:] The node directly above a node is the parent of that node.

4. The Text and Comment is part of
a) CharacterData
b) Document
c) Attr
d) Element

Answer

Answer: a [Reason:] The Text and Comment is part of the CharacterData Element.

5. The nodes that represent HTML elements are the
a) Subclass nodes
b) HTML nodes
c) Window nodes
d) Element nodes

Answer

Answer: d [Reason:] The nodes that represent HTML elements are Element nodes.

6. Which of the following is/are of Text nodes?
a) Text
b) Comment
c) Both Text and Comment
d) None of the mentioned

Answer

Answer: c [Reason:] Both Text and Comment are basically strings of text, and these nodes are much like the Text nodes that represent the displaying text of a document.

7. Which is one of way to query a document for an element or elements?
a) With a specified id attribute
b) Matching the specified CSS selector
c) With the specified tag name
d) All of the mentioned

Answer

Answer: d [Reason:] The DOM defines a number of ways to select elements; you can query a document for an element or elements:

  1. with a specified id attribute;
  2. with a specified name attribute;
  3. with the specified tag name;
  4. with the specified CSS class or classes; or
  5. matching the specified CSS selector

8. Which of the following can be used to select HTML elements based on the value of their name attributes?
a) getElementByName()
b) getElementsByName()
c) getElementsName()
d) getElementName()

Answer

Answer: b [Reason:] To select HTML elements based on the value of their name attributes, you can use the getElementsByName() method of the Document object:

var radiobuttons = document.getElementsByName("favorite_color");

9. Which of the following property refers to the root element of the document?
a) documentElement
b) elementdocument
c) rootdocument
d) none of the mentioned

Answer

Answer: a [Reason:] The documentElement property of the Document class refers to the root element of the document. This is always an HTML element.

10. The return type of getElementsByClassName() is
a) DOM
b) Document
c) Node
d) NodeList

Answer

Answer: d [Reason:] Like getElementsByTagName(), getElementsByClassName() can be invoked on both HTML documents and HTML elements, and it returns a live NodeList containing all matching descendants of the document or element.

Javascript MCQ Set 3

1. Consider the following code snippet

let succ = function(x) x+1, yes = function() true, no = function() false;

What convenience does the above code snippet provide?
a) Functional behaviour
b) Modular behaviour
c) No convenience
d) Shorthand expression

Answer

Answer: a [Reason:] The functions defined in this way behave exactly like functions defined with curly braces and the return keyword.

2. Consider the following code snippet

data.sort(function(a,b),b-a);

What does the above code do?
a) Sort in the alphabetical order
b) Sort in the chronological order
c) Sort in reverse alphabetical order
d) Sort in reverse numerical order

Answer

Answer: d [Reason:] The above code snippet sorts an array in reverse numerical order.

3. What is the code to be used to trim whitespaces ?

a) let trimmed = (l.trim() for (l in lines));
b) let trimmed = (trim(l));
c) let trimmed = l.trim();
d) let trimmed = for(l in lines));
Answer

Answer: a [Reason:] We can use the above code to trim whitespaces and filter out comments and blank lines.

4. What will be the reaction when a catch clause has no conditionals ?
a) Takes it to be 0
b) Takes it to be 1
c) Takes it to be true
d) Takes it to be false

Answer

Answer: c [Reason:] If a catch clause has no conditional, it behaves as if it has the conditional if true, and it is always triggered if no clause before it was triggered.

5. When will the finally block be called?
a) When there is no exception
b) When the catch doesnot match
c) When there is exception
d) None of the mentioned

Answer

Answer: d [Reason:] A finally block is called after try-catch execution.

6. What is the return type of typeof for standard JavaScript objects?
a) xml
b) object
c) dom
d) html

Answer

Answer: b [Reason:] The typeof operator returns “object” for all standard JavaScript objects as functions are, and the typeof operator returns “xml”.

7. Which method to use while working with XML fragments, instead of XML()?
a) XMLInterface()
b) XMLClass()
c) XMLList()
d) XMLArray()

Answer

Answer: c [Reason:] When working with XML fragments, use XMLList() instead of XML():

pt.element += new XMLList('<element id="6"><name>Carbon</name></element>'+'<element id="7"><name>Nitrogen</name></element>');

8. Which of the following is the descendant operator?
a) ..
b) …
c) *
d) @

Answer

Answer: b [Reason:] The .. operator is the descendant operator; you can use it in place of the normal . member-access operator :

var names = pt..name;

9. Which of the following is an example to perform the most common XML manipulations using the XML objects invocation?
a) insertChildBefore()
b) insertChildAfter()
c) appendChildAfter(…)
d) appendChildBefore(…)

Answer

Answer: a [Reason:] E4X is designed so that you can perform most common XML manipulations using language syntax. E4X also defines methods you can invoke on XML objects. Here, for example, is the insertChildBefore() method:

pt.insertChildBefore(pt.element[1],<element id="1"><name>Deuterium</name></element>);

10. What is the code required to delete all “weight” tags?
a) delete weight(pt).all;
b) delete pt.element[all];
c) delete pt;
d) delete pt..weight;

Answer

Answer: d [Reason:] Removing attributes and tags is very easy with the standard delete operator :

delete pt..weight; //delete all <weight> tags

Javascript MCQ Set 4

1. JavaScript is a _______________ language
a) Object-Oriented
b) High-level
c) Assembly-language
d) Object-Based

Answer

Answer: d [Reason:] JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java or PHP, but it is an object-based language.

2. The output for the following code snippet would most appropriately be

var a=5 , b=1
var obj = { a : 10 }
with(obj) 
{
      alert(b)
}

a) 10
b) Error
c) 1
d) 5

Answer

Answer: c [Reason:] The interpreter checks obj for property b, fails and takes it from outside of with.

3. A conditional expression is also called a
a) Alternate to if-else
b) Immediate if
c) If-then-else statement
d) None of the mentioned

Answer

Answer: b [Reason:] A conditional expression can evaluate to either True or False based on the wvaluation of the condition.

4. Which is a more efficient code snippet ?
Code 1 :

for(var num=10;num>=1;num--)
{
           document.writeln(num);
}

Code 2 :

var num=10;
while(num>=1)
{
       document.writeln(num);
       num++;
}

a) Code 1
b) Code 2
c) Both Code 1 and Code 2
d) Cannot Compare

Answer

Answer: a [Reason:] A for loop is always more efficient because it encapsules two individual statements(initialization and expression) within the braces.

5. A statement block is a
a) conditional block
b) block that contains a single statement
c) Both conditional block and single statement
d) block that combines multiple statements into a single compound statement

Answer

Answer: d [Reason:] A statement block is a block that combines more than one statements into a single compound statement for ease.

6. When an empty statement is encountered, a JavaScript interpreter
a) Ignores the statement
b) Prompts to complete the statement
c) Throws an error
d) Throws an exception

Answer

Answer: a [Reason:] The JavaScript interpreter takes no action when it executes an empty statement. The empty statement is occasionally useful when you want to create a loop that has an empty body.

7. The “var” and “function” are
a) Keywords
b) Declaration statements
c) Datatypes
d) Prototypes

Answer

Answer: b [Reason:] The var and function are declaration statements—they declare or define variables and functions. These statements define identifiers (variable and function names) that can be used elsewhere in your program and assign values to those identifiers.

8. Consider the following statements

switch(expression)
{
    statements
}

In the above switch syntax, the expression is compared with the case labels using which of the following operator(s) ?
a) ==
b) equals
c) equal
d) ===

Answer

Answer: d [Reason:] When a switch executes, it computes the value of expression and then looks for a case label whose expression evaluates to the same value (where sameness is determined by the === operator).

9. Consider the following statements

var count = 0;
while (count < 10) 
{
     console.log(count);
     count++;
}

In the above code snippet, what happens?
a) The values of count is logged or stored in a particular location or storage
b) The value of count from 0 to 9 is displayed in the console
c) An error is displayed
d) An exception is thrown

Answer

Answer: b [Reason:] None.

10. The enumeration order becomes implementation dependent and non-interoperable if :
a) If the object inherits enumerable properties
b) The object does not have the properties present in the integer array indices
c) The delete keyword is never used
d) Object.defineProperty() is not used

Answer

Answer: a [Reason:] None.

Javascript MCQ Set 5

1. When are the mouse events generated?
a) When user clicks the mouse over a document
b) When user moves over a document
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] Mouse events are generated when the user moves or clicks the mouse over a document. These events are triggered on the most deeply nested element that the mouse pointer is over, but they bubble up through the document.

2. The properties that specify the position and button state of the mouse are
a) clientX and clientY
b) clientY and clientX
c) altKey and ctrlKey
d) metaKey and shiftKey

Answer

Answer: a [Reason:] The clientX and clientY properties specify the position of the mouse in window coordinates.

3. Which of the following keys are set to true when the keyboard modifier keys are held down?
a) altKey
b) ctrlKey
c) metaKey
d) all of the mentioned

Answer

Answer: d [Reason:] The altKey, ctrlKey, metaKey, and shiftKey properties are set to true when the corresponding keyboard modifier keys are held down.

4. How to detect and respond to mouse drags?
a) Registering a mouseover handler
b) Releasing a mousedown handler
c) Registering a mousedown handler
d) None of the mentioned

Answer

Answer: c [Reason:] By registering a mousedown handler that registers a mousemove handler, you can detect and respond to mouse drags. Doing this properly involves being able to capture mouse events so that you continue to receive mousemove events even when the mouse has moved out of the element it started in.

5. When is the mouseover event fired?
a) When mouse is moved over a new element
b) When mouse is clicked
c) When mouse is both moved and clicked
d) None of the mentioned

Answer

Answer: a [Reason:] When the user moves the mouse so that it goes over a new element, the browser fires a mouseover event on that element.

6. When is the mouseout event fired?
a) When mouse is no longer over an element
b) When mouse is over an element
c) When mouse is hovered
d) None of the mentioned

Answer

Answer: a [Reason:] When the mouse moves so that it is no longer over an element, the browser fires a mouseout event on that element.

7. The focus and blur events are also part of
a) Element events
b) Handler events
c) Window events
d) Scroll events

Answer

Answer: c [Reason:] The focus and blur events are also used as Window events: they are triggered on a window when that browser window receives or loses keyboard focus from the operating system.

8. The element that can also register handlers for load and error events is
a) html
b) img
c) body
d) form

Answer

Answer: b [Reason:] Individual document elements, such as img elements, can also register handlers for load and error events.

9. The events that is emulated by the jQuery library are
a) focusarea and focusover
b) focusall and focusnone
c) focusdown and focusup
d) focusin and focusout

Answer

Answer: b [Reason:] The jQuery library emulates focusin and focusout events for browsers that do not support them.

10. Which event is triggered sooner when the document and its elements are ready to manipulate?
a) DOMContentLoaded
b) readystatechange
c) Both DOMContentLoaded & readystatechange
d) None of the mentioned

Answer

Answer: c [Reason:] DOMContentLoaded and readystatechange are alternatives to the load event: they are triggered sooner, when the document and its elements are ready to manipulate, but before external resources are fully loaded.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.