JavaScript Exam: MCQ Quiz!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Ronnelagulto
R
Ronnelagulto
Community Contributor
Quizzes Created: 3 | Total Attempts: 564
Questions: 25 | Attempts: 164

SettingsSettingsSettings
JavaScript Exam: MCQ Quiz! - Quiz

.


Questions and Answers
  • 1. 

    Do functions in JavaScript necessarily return a value?

    • A.

      It is mandatory

    • B.

      Not necessary

    • C.

      Few functions return values by default

    • D.

      All of the choices

    Correct Answer
    C. Few functions return values by default
    Explanation
    In JavaScript, functions do not necessarily return a value. While it is possible to explicitly specify a return value using the return statement, not all functions have a return statement. In such cases, the function will return undefined by default. Therefore, only a few functions in JavaScript actually return values by default.

    Rate this question:

  • 2. 

    Which of the following is an example of a javascript function?

    • A.

      Alert()

    • B.

      If()

    • C.

      Script()

    • D.

      None of the choices

    Correct Answer
    A. Alert()
    Explanation
    The correct answer is "alert()". This is because "alert()" is a built-in JavaScript function that displays a dialog box with a message. It is commonly used to provide information or to prompt the user for input. The other options, "if()" and "script()", are not examples of JavaScript functions. "if()" is a conditional statement used for decision-making, and "script()" is not a valid JavaScript function. Therefore, the correct answer is "alert()".

    Rate this question:

  • 3. 

    It is a group of reusable code which can be called anywhere in your program.

    • A.

      Events

    • B.

      Functions

    • C.

      Actions

    • D.

      Objects

    Correct Answer
    B. Functions
    Explanation
    Functions are a group of reusable code that can be called anywhere in a program. They allow for the organization and modularization of code, making it easier to manage and maintain. By encapsulating a set of instructions within a function, it can be called multiple times from different parts of the program, reducing redundancy and improving code efficiency. Additionally, functions can accept inputs (parameters) and return outputs, making them versatile and adaptable to different scenarios. Therefore, functions are the correct answer in this case.

    Rate this question:

  • 4. 

    Consider the following code snippet: var tensquared = (function(x) {return x*x;}(10)); Will the given code work?

    • A.

      Yes, perfectly

    • B.

      Error

    • C.

      Exception will be thrown

    • D.

      Memory leak

    Correct Answer
    A. Yes, perfectly
    Explanation
    The given code will work perfectly. It defines a function called tensquared that takes an argument x and returns the square of x. The function is immediately invoked with the argument 10, resulting in the variable tensquared being assigned the value 100.

    Rate this question:

  • 5. 

    Consider the following code snippet.

    • A.

      123

    • B.

      123xyz

    • C.

      Exception

    • D.

      NaN

    Correct Answer
    B. 123xyz
    Explanation
    The correct answer is "123xyz" because it is the only value in the code snippet that is not a valid number. The other values, "123", "Exception", and "NaN", can all be interpreted as numbers in some context. However, "123xyz" contains non-numeric characters and cannot be parsed as a number.

    Rate this question:

  • 6. 

    For the below-mentioned code snippet: var o = new Object(); The equivalent statement is

    • A.

      Var o = Object();

    • B.

      Var o;

    • C.

      Var o= new Object;

    • D.

      Object o=new Object();

    Correct Answer
    C. Var o= new Object;
    Explanation
    The correct answer is "var o = new Object;" because it correctly initializes a new object using the Object constructor. The other options are incorrect because they either do not use the "new" keyword or have incorrect syntax.

    Rate this question:

  • 7. 

    The most common way to define a function in JavaScript is by using the________ keyword.

    • A.

      Event

    • B.

      Func

    • C.

      Function

    • D.

      Script

    Correct Answer
    C. Function
    Explanation
    The most common way to define a function in JavaScript is by using the "function" keyword. This keyword is used to declare a new function and specify its name and parameters. It is followed by a block of code that defines the behavior of the function. By using the "function" keyword, developers can create reusable blocks of code that can be executed whenever needed.

    Rate this question:

  • 8. 

    What is the output of the following snippet: <html> <head> <script type="text/javascript"> function sayHello() { document.write ("Hello there!"); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type="button" onclick="sayHello()" value="Say Hello"> </form> <p>Use different text in write method and then try...</p> </body> </html>

    • A.

      When the button is clicked an output sayHell will be displayed Option 1

    • B.

      When the button is clicked an output "Hello" will be displayed

    • C.

      When the button is clicked an output "Button" will be displayed

    • D.

      When the button is clicked an output "Hello there!" will be displayed

    Correct Answer
    D. When the button is clicked an output "Hello there!" will be displayed
    Explanation
    When the button is clicked, the function "sayHello()" is called. Inside the function, the "document.write()" method is used to write the text "Hello there!" to the document. Therefore, when the button is clicked, the output "Hello there!" will be displayed.

    Rate this question:

  • 9. 

    Which of the following statement about the function is true?

    • A.

      Functions would not eliminates the need of writing the same code again and again

    • B.

      A function can take multiple parameters separated by comma.

    • C.

      It will not allow a programmer to divide a big program into a number of small and manageable functions

    • D.

      The parameter list of the function should be empty

    Correct Answer
    B. A function can take multiple parameters separated by comma.
    Explanation
    The given correct answer states that a function can take multiple parameters separated by a comma. This means that when defining a function, it is possible to specify multiple variables that can be passed as arguments when calling the function. This allows for flexibility and reusability of code, as different values can be passed to the function each time it is called.

    Rate this question:

  • 10. 

    The follwing syntax is used to?<script type="text/javascript"><!--var variablename = new Function(Arg1, Arg2..., "Function Body");//--></script>

    • A.

      To create a function using Function() constructor

    • B.

      To implement nested functions.

    • C.

      To implement function literal

    • D.

      None of the choices

    Correct Answer
    A. To create a function using Function() constructor
    Explanation
    The given syntax is used to create a function using the Function() constructor. This syntax allows for the creation of a new function object by specifying the arguments and the function body within the constructor.

    Rate this question:

  • 11. 

    Consider the following code snippet: function constfuncs() { var funcs = []; for(var i = 0; i < 10; i++) funcs[i] = function() { return i; }; return funcs; } var funcs = constfuncs(); funcs[5]() What does the last statement return?

    • A.

      9

    • B.

      0

    • C.

      10

    • D.

      None of the choices

    Correct Answer
    C. 10
    Explanation
    The last statement returns 10. This is because the variable "funcs" is assigned the value returned by the "constfuncs()" function, which is an array of functions. Each function in the array returns the value of the variable "i" when it was created. In the for loop, "i" is incremented from 0 to 9. So when the function at index 5 is called, it returns the value of "i" at that time, which is 10.

    Rate this question:

  • 12. 

    The behavior of the instances present of a class inside a method is defined by:

    • A.

      Method

    • B.

      Classes

    • C.

      Interfaces

    • D.

      Classes and Interfaces

    Correct Answer
    B. Classes
    Explanation
    The behavior of the instances present of a class inside a method is defined by classes. Classes are the blueprint for creating objects, and they define the properties (attributes) and behaviors (methods) of those objects. In this case, the behavior of the instances of a class is determined by the class itself, as methods are defined within the class and operate on its instances. Interfaces, on the other hand, define contracts for implementing classes but do not directly define the behavior of instances. Therefore, classes are the correct answer in this context.

    Rate this question:

  • 13. 

    The keyword or the property that you use to refer to an object through which they were invoked is:

    • A.

      From

    • B.

      To

    • C.

      This

    • D.

      Object

    Correct Answer
    C. This
    Explanation
    The keyword "this" is used to refer to the object through which a method or property was invoked. It allows access to the current instance of the object and is commonly used within the object's methods to refer to its own properties or invoke other methods.

    Rate this question:

  • 14. 

    JavaScript's interaction with HTML is handled through ___ that occurs when the user or the browser manipulates a page.

    • A.

      Function

    • B.

      Class

    • C.

      Object

    • D.

      Event

    Correct Answer
    D. Event
    Explanation
    JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page. Events are triggered by actions such as clicking a button, submitting a form, or hovering over an element. JavaScript can listen for these events and respond accordingly by executing functions or modifying the HTML content. This allows for dynamic and interactive web pages.

    Rate this question:

  • 15. 

    This is the most frequently used event type that occurs when a user clicks the left button of his mouse.

    • A.

      OnSubmit

    • B.

      Onmouseover

    • C.

      OnClick

    • D.

      All of the given

    Correct Answer
    C. OnClick
    Explanation
    The correct answer is onClick. This event type is commonly used when a user clicks the left button of their mouse. The onSubmit event type is typically used in forms when the user submits the form, while the onmouseover event type is triggered when the user moves their mouse over an element. Therefore, the most appropriate event type for the given scenario is onClick.

    Rate this question:

  • 16. 

    It is is an important keyword in JavaScript which can be used as a unary operator that appears before its single operand, which may be of any type.

    • A.

      Return

    • B.

      Void

    • C.

      Function

    • D.

      Script

    Correct Answer
    B. Void
    Explanation
    The keyword "void" in JavaScript is used as a unary operator before an operand. It is commonly used to specify that a function does not return a value. When "void" is used before a function call, it ensures that the function is executed but the result is discarded. This can be useful in situations where the function is used for its side effects rather than its return value.

    Rate this question:

  • 17. 

    It is the capability to store related information, whether data or methods, together in an object.

    • A.

      Encapsulation

    • B.

      Aggregation

    • C.

      Inheritance

    • D.

      Polymorphism

    Correct Answer
    A. Encapsulation
    Explanation
    Encapsulation refers to the ability to store related information, such as data and methods, together in an object. This allows for better organization and modularity in programming, as the object can encapsulate its own data and methods, making it easier to manage and manipulate. Encapsulation also helps to ensure data integrity and security, as access to the object's internal data can be controlled through encapsulation.

    Rate this question:

  • 18. 

    It is the capability to store one object inside another object.

    • A.

      Polymorphism

    • B.

      Encapsulation

    • C.

      Inheritance

    • D.

      Aggregation

    Correct Answer
    D. Aggregation
    Explanation
    Aggregation refers to the capability of storing one object inside another object. In this concept, one object is considered as the whole, while the other object is considered as a part. The whole object can exist without the part object, and the part object can also exist independently. This relationship allows for code reusability and flexibility in designing complex systems.

    Rate this question:

  • 19. 

    It is the capability to write one function or method that works in a variety of different ways.

    • A.

      Polymorphism

    • B.

      Encapsulation

    • C.

      Inheritance

    • D.

      Aggregation

    Correct Answer
    A. Polymorphism
    Explanation
    Polymorphism refers to the ability of an object to take on many forms. In programming, it specifically refers to the capability of a function or method to behave differently based on the type of object it is called on. This allows for code reusability and flexibility, as the same function can be used with different types of objects, providing different behaviors based on the specific object being used.

    Rate this question:

  • 20. 

    It is the capability of a class to rely upon another class (or number of classes) for some of its properties and methods.

    • A.

      Encapsulation

    • B.

      Inheritance

    • C.

      Aggregation

    • D.

      Polymorphism

    Correct Answer
    B. Inheritance
    Explanation
    Inheritance is the capability of a class to rely upon another class (or number of classes) for some of its properties and methods. Inheritance allows a class to inherit the attributes and behaviors of another class, known as the parent or base class. This enables code reusability and promotes the concept of hierarchical relationships between classes. Subclasses can extend and specialize the functionality inherited from the parent class, while also adding their own unique attributes and methods.

    Rate this question:

  • 21. 

    The syntax for adding a property to an object is:

    • A.

      ObjectName.objectProperty = new propertyValue();

    • B.

      ObjectName.objectProperty = new propertyValue;

    • C.

      ObjectName.objectProperty = propertyValue;

    • D.

      ObjectName.objectProperty = propertyValue();

    Correct Answer
    C. ObjectName.objectProperty = propertyValue;
    Explanation
    The correct answer is "objectName.objectProperty = propertyValue;". This syntax is used to add a property to an object. It assigns the value of "propertyValue" to the "objectProperty" of "objectName". The other options either include unnecessary "new" keyword or parentheses, which are not required in this context.

    Rate this question:

  • 22. 

    Which of the following is an example to show how to use the write() method of the document object to write any content on the document?

    • A.

      Alert ("This is test");

    • B.

      Document.write ("Hello world");

    • C.

      Document.write (This is test);

    • D.

      None of the given

    Correct Answer
    B. Document.write ("Hello world");
    Explanation
    The correct answer is "document.write ("Hello world");". This is because the write() method is used to write content directly to the HTML document. In this example, the write() method is used to write the string "Hello world" onto the document. The other options are not valid examples of using the write() method.

    Rate this question:

  • 23. 

    The____ operator is used to create an instance of an object.

    • A.

      New

    • B.

      This

    • C.

      Void

    • D.

      Alert

    Correct Answer
    A. New
    Explanation
    The "new" operator is used to create an instance of an object. It allocates memory for the object and initializes its properties and methods. This allows us to create multiple instances of the same object type, each with its own set of values and behaviors.

    Rate this question:

  • 24. 

    A _______is a function that creates and initializes an object.

    • A.

      Constructor

    • B.

      Object

    • C.

      Events

    • D.

      Var

    Correct Answer
    A. Constructor
    Explanation
    A constructor is a special type of function that is used to create and initialize objects. It is called when an object is created from a class and is responsible for setting initial values and performing any necessary setup tasks. Constructors are commonly used to ensure that objects are properly initialized before they are used, and they can also accept parameters to customize the initialization process. In this context, a constructor is the correct answer as it specifically refers to a function that creates and initializes an object.

    Rate this question:

  • 25. 

    Which of the following syntax is an example of properly declaring a function?

    • A.

      Fun sayHello();

    • B.

      Func say Hello()

    • C.

      Book name is : Perl Book name is : Perl function sayHello()

    • D.

      Function sayHello;

    Correct Answer
    C. Book name is : Perl Book name is : Perl function sayHello()

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Nov 09, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 03, 2017
    Quiz Created by
    Ronnelagulto
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.