Javascript MCQ Number 01119

Javascript MCQ Set 1

1. The function definitions in JavaScript begins with
a) Identifier and Parantheses
b) Return type and Identifier
c) Return type, Function keyword, Identifier and Parantheses
d) Identifier and Return type

Answer

Answer: a [Reason:] The function definitions begin with the keyword function followed by an identifier that names the function and a pair of parantheses around a comma-separated list of zero or more identifiers.

2. Consider the following code snippet

function printprops(o) 
{
    for(var p in o)
      console.log(p + ": " + o[p] + "n");
}

What will the above code snippet result ?
a) Prints the contents of each property of o
b) Returns undefined
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] The above code snippet returns undefined.

3. When does the function name become optional in JavaScript?
a) When the function is defined as a looping statement
b) When the function is defined as expressions
c) When the function is predefined
d) All of the mentioned

Answer

Answer: b [Reason:] The function name is optional for functions defined as expressions. A function declaration statement actually declares a variable and assigns a function object to it.

4. What is the purpose of a return statement in a function?
a) Returns the value and continues executing rest of the statements, if any
b) Returns the value and stops the program
c) Returns the value and stops executing the function
d) Stops executing the function and returns the value

Answer

Answer: d [Reason:] The return statement causes the function to stop executing and to return the value of its expression (if any) to the caller.

5. What will happen if a return statement does not have an associated expression?
a) It returns the value 0
b) It will throw an exception
c) It returns the undefined value
d) None of the mentioned

Answer

Answer: c [Reason:] If the return statement does not have an associated expression, it returns the undefined value.

6. A function with no return value is called
a) Procedures
b) Method
c) Static function
d) Dynamic function

Answer

Answer: a [Reason:] Functions with no return value are sometimes called procedures.

7. Consider the following code snippet

function hypotenuse(a, b) 
{
       function square(x) 
       { 
            return x*x; 
       }
       return Math.sqrt(square(a) + square(b));
}

What does the above code result?
a) Sum of square of a and b
b) Square of sum of a and b
c) Sum of a and b square
d) None of the mentioned

Answer

Answer: a [Reason:] The above code snippet contains nested function in which the function hypotenuse(a,b) has another function inside its scope, function square(x). The interesting thing about nested functions is their variable scoping rules. They can acceess the parameters and variables of the function (or functions) they are nested within.

8. Which of the following is the correct code for invoking a function without this keyword at all, and also too determine whether the strict mode is in effect?

a) var strict = (function { return this; });
b) mode strict = (function() { return !this;  }());
c) var strict = (function() { return !this; }());
d) mode strict = (function { });
Answer

Answer: c [Reason:] The above code defines and invokes a function to determine if we’re in strict mode.

9. Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?

a) o(x,y);
b) o.m(x) && o.m(y);
c) m(x,y);
d) o.m(x,y);
Answer

Answer: d [Reason:] The code above is an invocation expression: it includes a function expression o.m and two argument expressions, x and y.

10. Consider the following code snippet

o.m(x,y);

Which is an equivalent code for the above code snippet?

a) o.m(x) && o.m(y);
b) o["m"](x,y);
c) o(m)["x","y"];
d) o.m(x && y);
Answer

Answer: b [Reason:] Another way to write o.m(x,y) is o[“m”](x,y).

Javascript MCQ Set 2

1. Which function among the following lets to register a function to be invoked once?
a) setTimeout()
b) setTotaltime()
c) setInterval()
d) none of the mentioned

Answer

Answer: a [Reason:] setTimeout() and setInterval() allow you to register a function to be invoked once or repeatedly after a specified amount of time has elapsed.

2. Which function among the following lets to register a function to be invoked repeatedly after a certain time?
a) setTimeout()
b) setTotaltime()
c) setInterval()
d) none of the mentioned

Answer

Answer: c [Reason:] setTimeout() and setInterval() allow you to register a function to be invoked once or repeatedly after a specified amount of time has elapsed.

3. Which is the handler method used to invoke when uncaught JavaScript exceptions occur?
a) Onhalt
b) Onerror
c) Both onhalt and onerror
d) None of the mentioned

Answer

Answer: b [Reason:] The onerror handler method can be registered to be invoked when uncaught JavaScript exceptions occur.

4. Which property is used to obtain browser vendor and version information?
a) modal
b) version
c) browser
d) navigator

Answer

Answer: d [Reason:] The navigator property is used to obtain browser vendor and version information.

5. Which method receives the return value of setInterval() to cancel future invocations?
a) clearInvocation()
b) cancelInvocation()
c) clearInterval()
d) None of the mentioned

Answer

Answer: c [Reason:] Like setTimeout(), setInterval() returns a value that can be passed to clearInterval() to cancel any future invocations of the scheduled function.

6. The setTimeout() belongs to which object?
a) Element
b) Window
c) Location
d) None of the mentioned

Answer

Answer: b [Reason:] The setTimeout() method of the Window object schedules a function to run after a specified number of milliseconds elapses.

7. Which method receives the return value of setTimeout() to cancel future invocations?
a) clearTimeout()
b) clearInterval()
c) clearSchedule()
d) none of the mentioned

Answer

Answer: a [Reason:] setTimeout() returns a value that can be passed to clearTimeout() to cancel the execution of the scheduled function.

8. What will happen if we call setTimeout() with a time of 0 ms?
a) Placed in stack
b) Placed in queue
c) Will run continuously
d) None of the mentioned

Answer

Answer: b [Reason:] If you call setTimeout() with a time of 0 ms, the function you specify is not invoked right away. Instead, it is placed on a queue to be invoked “as soon as possible” after any currently pending event handlers finish running.

9. To which object does the location property belong?
a) Window
b) Position
c) Element
d) Location

Answer

Answer: a [Reason:] The location property of the Window object refers to a Location object, which represents the current URL of the document displayed in the window, and which also defines methods for making the window load a new document.

10. What is the result of the following code snippet?

window.location === document.location

a) False
b) True
c) 0
d) 1

Answer

Answer: b [Reason:] The above code always results in a true value.

Javascript MCQ Set 3

1. DOM Level 3 Events standardizes which of the following events?
a) focusarea and focusover
b) focusall and focusnone
c) focusdown and focusup
d) focusin and focusout

Answer

Answer: d [Reason:] The DOM Level 3 Events specification standardizes the focusin and focusout events as bubbling alternatives to the focus and blur events.

2. Which of the following are the unnecessary events currently?
a) DOMActivate
b) DOMFocusIn
c) DOMNodeInserted
d) All of the mentioned

Answer

Answer: d [Reason:] Browsers are still allowed to generate events like DOMActivate, DOMFocusIn, and DOMNodeInserted, but these are no longer required.

3. Which object is passed as the argument to handlers for keydown, keyup, and keypress events?
a) KeyboardEvent
b) Key Event
c) Mouse Event
d) Alphabet Event

Answer

Answer: a [Reason:] What is new in the DOM Level 3 Events specification is standardized support for twodimensional mouse wheels via the wheel event and better support for text input events with a textinput event and with a new KeyboardEvent object that is passed as the argument to handlers for keydown, keyup, and keypress events.

4. Which property reports rotation around three different mouse wheel axes?
a) ctrlKey
b) alterX
c) alterY
d) deltaX

Answer

Answer: d [Reason:] A handler for a wheel event receives an event object with all the usual mouse event properties, and also deltaX, deltaY, and deltaZ properties that report rotation around three different mouse wheel axes.

5. Which of the following property specifies the string of text that was entered?
a) message
b) data
c) string
d) text

Answer

Answer: b [Reason:] A textinput event handler has a data property that specifies the string of text that was entered.

6. Which of the following is defined by the specification?
a) dataMethod
b) input
c) inputMethod
d) inputdataMethod

Answer

Answer: c [Reason:] The specification defines an inputMethod property on the event object and a set of constants representing different kinds of text input (keyboard, paste or drop, handwriting or voice recognition, and so on).

7. Which two events will have the generated text for key events?
a) key and char
b) char and text
c) text and key
d) key and value

Answer

Answer: a [Reason:] For key events that generate printable characters, key and char will be equal to the generated text.

8. Which of the following are the drag and drop events?
a) drop
b) dragstart
c) both drop and dragstart
d) none of the mentioned

Answer

Answer: c [Reason:] The API defines the following seven event types :

  1. dragstart
  2. drag
  3. dragend
  4. dragenter
  5. dragover
  6. dragleave
  7. drop

9. Which property holds a DataTransfer object that contains information about the data being transferred and the formats in whichh it is available?
a) dataTransfer
b) transferData
c) dataExchange
d) exchangeData

Answer

Answer: a [Reason:] The property, dataTransfer, holds a DataTransfer object that contains information about the data being transferred and the formats in which it is available.

10. Which API allows scripts in a document from one server to exchange messages with scripts?
a) Cross-Document Messaging API
b) Web application API
c) Both Cross-Document Messaging API & Web application API
d) None of the mentioned

Answer

Answer: a [Reason:] The Cross-Document Messaging API allows scripts in a document from one server to exchange messages with scripts in a document from another server. This works around the limitations of the same-origin policy in a secure way. Each message that is sent triggers a message event on the Window of the receiving document.

Javascript MCQ Set 4

1. What is the code snippet to go back to a history twice?

a) history(2);
b) history(-2);
c) history.go(-2);
d) history.go(2);
Answer

Answer: c [Reason:] The above code snippet goes back 2, like clicking the Back button twice.

2. If the window has child windows, how will the browsing histories be affected?
a) Numerically interleaved
b) Chronologically interleaved
c) Both Numerically and Chronologically interleaved
d) None of the mentioned

Answer

Answer: b [Reason:] If a window contains child windows, the browsing histories of the child windows are chronologically interleaved with the history of the main window.

3. The length property belongs to which of the following objects?
a) Window
b) Element
c) History
d) Document

Answer

Answer: c [Reason:] The length property of the History object specifies the number of elements in the browsing history list, but for security reasons scripts are not allowed to access the stored URLs.

4. What is the datatype of the go() method’s parameter?
a) String
b) Integer
c) Double
d) Float

Answer

Answer: b [Reason:] The go() method takes an integer argument and can skip any number of pages forward and backward in the history list.

5. What is the special feature of the modern web applications?
a) Can alter contents without loading document
b) Must load the document to manipulate
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] Modern web applications can dynamically alter their own content without loading a new document.

6. The navigator property belongs to which of the following object?
a) Document
b) Window
c) Navigator
d) Location

Answer

Answer: c [Reason:] The navigator property of a Window object refers to a Navigator object that contains browser vendor and version number information.

7. What is the vendor-neutral synonym for navigator?
a) staticData
b) purposeInformation
c) dataInformation
d) clientInformation

Answer

Answer: d [Reason:] IE supports clientInformation as a vendor-netural synonym for navigator.

8. Which is the preferred testing nowadays for scripting?
a) Software testing
b) Feature testing
c) Blackbox testing
d) Whitebox testing

Answer

Answer: b [Reason:] In the past, the Navigator object was commonly used by scripts to determine if they were running in Internet Explorer or Netscape. This “browser-sniffing” approach is problematic because it requires constant tweaking as new browsers and new versions of existing browsers are introduced. Today, feature testing is preferred: rather than making assumptions about particular browser versions and their features, you simply test for the feature (i.e., the method or property) you need.

9. Which of the below properties can be used for browser sniffing?
a) platform
b) appVersion
c) both platform and appVersion
d) none of the mentioned

Answer

Answer: c [Reason:] The platform and appVersion can be used for browser sniffing.

10. Where is the information of the userAgent property located?
a) appId
b) appName
c) platform
d) appVersion

Answer

Answer: d [Reason:] The string that the browser sends in its USER-AGENT HTTP header. This property typically contains all the information in appVersion and may contain additional details as well. Like appVersion, there is no standard format. Since this property contains the most information, browser-sniffing code typically uses it.

Javascript MCQ Set 5

1. Consider the following snippet code

var string1 =123;
var intvalue = 123;
alert( string1 + intvalue );

The result would be
a) 123246
b) 246
c) 123123
d) Exception

Answer

Answer: c [Reason:] None.

2. A function definition expression can be called
a) Function prototype
b) Function literal
c) Function definition
d) Function declaration

Answer

Answer: b [Reason:] A function definition expression is a “function literal” in the same way that an object initializer is an “object literal.” A Function definition expression typically consists of the keyword function followed by a comma-separated list of zero or more identifiers (the parameter names) in parentheses and a block of JavaScript code (the function body) in curly braces.

3. The property of a primary expression is
a) stand-alone expressions
b) basic expressions containing all necessary functions
c) contains variable references alone
d) complex expressions

Answer

Answer: a [Reason:] The simplest expressions, known as primary expressions, are those that stand alone — they do not include any simpler expressions. Primary expressions in JavaScript are constant or literal values, certain laguage keywords, and variable references.

4. Consider the following statements

var text = "testing: 1, 2, 3"; // Sample text
var pattern = /d+/g // Matches all instances of one or more digits

In order to check if the pattern matches with the string “text”, the statement is
a) text==pattern
b) text.equals(pattern)
c) text.test(pattern)
d) pattern.test(text)

Answer

Answer: d [Reason:] The given pattern is applied on the text given in the parenthesis.

5. The JavaScript’s syntax calling ( or executing ) a function or method is called
a) Primary expression
b) Functional expression
c) Invocation expression
d) Property Access Expression

Answer

Answer: c [Reason:] An invocation expression is JavaScript’s syntax for calling (or executing) a function or method) It starts with a function expression that identifies the function to be called.

6. What kind of an expression is “new Point(2,3)”?
a) Primary Expression
b) Object Creation Expression
c) Invocation Expression
d) Constructor Calling Expression

Answer

Answer: b [Reason:] An object creation expression creates a new object and invokes a function (called a constructor) to initialize the properties of that object. Object creation expressions are like invocation expressions except that they are prefixed with the keyword new.

7. Which of the operator is used to test if a particular property exists or not?
a) in
b) exist
c) within
d) exists

Answer

Answer: a [Reason:] The operator “in” tests whether a particular property exists.

8. Among the following, which one is a ternary operator?
a) +
b) :
c) –
d) ?:

Answer

Answer: d [Reason:] JavaScript supports one ternary operator, the conditional operator ?:, which combines three expressions into a single expression.

9. “An expression that can legally appear on the left side of an assignment expression.” is a well known explanation for variables, properties of objects, and elements of arrays. They are called
a) Properties
b) Prototypes
c) Lvalue
d) Definition

Answer

Answer: c [Reason:] lvalue is a historical term that means “an expression that can legally appear on the left side of an assignment expression.” In JavaScript, variables, properties of objects, and elements of arrays are lvalues.

10. Consider the following statements

x = ~-y;
w = x = y = z;
q = a?b:c?d:e?f:g;

The above code snippet is equivalent to

a) x = ~(-y); w = (x = (y = z));
q = a?b:(c?d:(e?f:g));
b) x = a?b:(c?d:(e?f:g));
q = ~(-y); w = (x = (y = z));
c) x = (x = (y = z));w = ~(-y);
q = a?b:(c?d:(e?f:g));
d) x = ~(-y); w = (x = (y = z)); 
q = (c?d:(e?f:g));
Answer

Answer: a [Reason:] None.

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.