JavaScript Exam: MCQ Quiz!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Ronnelagulto
R
Ronnelagulto
Community Contributor
Quizzes Created: 3 | Total Attempts: 654
| Attempts: 174 | Questions: 25
Please wait...
Question 1 / 25
0 %
0/100
Score 0/100
1. 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?

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.

Submit
Please wait...
About This Quiz
JavaScript Exam: MCQ Quiz! - Quiz

This 'Javascript Exam: MCQ Quiz!' assesses knowledge on JavaScript functions, syntax, and code execution. It challenges learners with questions about function behavior, specific code snippets, and general programming... see moreconcepts in JavaScript, enhancing both basic and advanced JavaScript skills. see less

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

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.

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

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.

Submit
4. 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>

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

Submit
11. A _______is a function that creates and initializes an object.

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.

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

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.

Submit
13. Consider the following code snippet.

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.

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

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.

Submit
15. 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?

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.

Submit
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.

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.

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

Explanation

not-available-via-ai

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

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.

Submit
19. Which of the following statement about the function is true?

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.

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

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.

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

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.

Submit
22. The syntax for adding a property to an object is:

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.

Submit
23. Do functions in JavaScript necessarily return a value?

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.

Submit
24. Which of the following is an example of a javascript function?

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()".

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

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.

Submit
View My Results

Quiz Review Timeline (Updated): Nov 9, 2023 +

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
Cancel
  • All
    All (25)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following is an example to show how to use the...
The keyword or the property that you use to refer to an object through...
The most common way to define...
What is the output of the following snippet: ...
It is a group of reusable code which can be called anywhere in your...
JavaScript's interaction with HTML is handled through ___ that...
It is the capability of a class to rely upon another class (or...
The____ operator is used to create an instance of an object.
It is the capability to write one function or method that works...
Consider the following code snippet: ...
A _______is a function that creates and initializes an object.
The follwing syntax is used to? <script...
Consider the following code snippet.
It is the capability to store related information, whether data...
Consider the following code snippet:...
It is is an important keyword in JavaScript which can be used as a...
Which of the following syntax is an example of properly declaring a...
The behavior of the instances present of a class inside a method is...
Which of the following statement about the function is true?
For the below-mentioned code snippet: ...
It is the capability to store one object inside another object.
The syntax for adding a property to an object is:
Do functions in JavaScript necessarily return a value?
Which of the following is an example of a javascript function?
This is the most frequently used event type that occurs when a user...
Alert!

Advertisement