Home JavaScript MCQs JavaScript MCQs III

JavaScript MCQs III

by anupmaurya

Wonderful JavaScript MCQs Series for Beginner .Practice these MCQs to enhance and test the knowledge of JavaScript.

1.What is the output for the following code?

(function f() {
  function f() {
    return 1;
  }
  return f();

  function f() {
    return 2;
  }
})();
  1. 2
  2. NaN
  3. 1
  4. Error

1) 2

2.What is the output of the following expression?

function multi(x, y) {
  var c = x * y;
}
multi(20, 3);
  1. Nothing
  2. 20
  3. 3
  4. 60

1) Nothing

3.Which of the following regarding scope is true?

  1. Data that is stored in a variable when a function is called is never cleared out.
  2. Function parameters are visible in the function in which they are used.
  3. All variables you use in your program have to be declared as global variables.
  4. Variables that have a local scope are only visible in the function in which they are declared.

4) Variables that have a local scope are only visible in the function in which they are declared.

4.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 a function declaration

  1. I, II, III, IV
  2. I, II, III
  3. I, II, IV
  4. I, II

2) I, II, III

5.Anonymous functions can be created in JavaScript. What do anonymous function do?

  1. Process a variable before passing it on to another function
  2. Overwrite variables that are to be kept updated
  3. Automatically define the scope of a value inside a parameter

1) Process a variable before passing it on to another function

6.What is the output you get for the following code?

(function() {
  return typeof arguments;
})
();
  1. array
  2. undefined
  3. object
  4. arguments

3) object

7.Object’s properties are similar to variables and methods are similar to _________.

  1. Properties
  2. Operators
  3. Functions
  4. Conditionals

3) Functions

8.________ is a function contained within an object.

  1. None of the options
  2. Object
  3. Function
  4. Method

4) Method

9.A function in JavaScript is an object. State if the statement is true or false?

  1. False
  2. True

2) True

10.What is the output for the following expression?

function test(x) {
  while (x < 5) {
    x++;
  }
  return x;
}
alert(test(2));
  1. 2
  2. 3
  3. 6
  4. 5

4) 5

11.For any structured document, __________ defines a standard set of objects.

  1. XML DOM
  2. HTML DOM
  3. Core DOM

3) Core DOM

12.Which statement about the name and id attributes of form fields is false?

  1. The id attribute is what is sent when the form is submitted.
  2. The name attribute can be used to access the field using getElementsByName().
  3. It is customary to give form fields both attributes, with the same value if possible.
  4. Either attribute may be omitted if it is unused.

1) The id attribute is what is sent when the form is submitted.

13.Using HTML button tag, JavaScript command can be executed by using ____ function.

  1. “alert(Button1);”
  2. “alert(‘Button1’);”
  3. “alert(‘Button1’);
  4. “alert(‘Button”);”

2) “alert(‘Button1’);”

14.By modifying the DOM, the contents on the page also gets modified

  1. True
  2. False

1) True

15.Document object is part of ____________ object.

  1. System
  2. Window
  3. Tree

2) Window

16.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?

  1. answers.innerHTML = “Hello”;
  2. d.appendChild(“Hello “);
  3. d.innerHTML = “Hello “;
  4. p = createElement(“p”); p.innerHTML = “Hello”; d.appendChild(p);

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

17.By modifying the DOM, the contents on the page also gets modified

  1. False
  2. True

2) True

18.Which statement accesses HTML classes?

  1. class.name
  2. getElementsByClassName
  3. getElementById

2) getElementsByClassName

19.How many ‘onload’ events can be written in a page?

  1. 1
  2. Many
  3. None
  4. 2

1) 1

20.Which is the most preferred way of handling events?

  1. Registering a listener to an element.
  2. Writing the JavaScript as an attribute to an element.
  3. Referencing an element with the event and assigning a function as a value.

1) Registering a listener to an element.

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.