JavaScript Trivia Exam: 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: 184 | Questions: 45
Please wait...
Question 1 / 45
0 %
0/100
Score 0/100
1. JavaScript's interaction with HTML is handled through events that occur whenthe 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. This means that JavaScript can respond to various actions or changes happening on an HTML page, such as clicking a button, submitting a form, or loading a new document. By using event handlers and event listeners, JavaScript code can be executed in response to these events, allowing for dynamic and interactive web pages. Therefore, the statement "True" is correct as it accurately describes the way JavaScript interacts with HTML.

Submit
Please wait...
About This Quiz
JavaScript Quizzes & Trivia

Dive into the Javascript Trivia Exam and test your knowledge on JavaScript functions, syntax, and code execution. This quiz assesses key programming concepts and practical application skills, making it ideal for learners looking to improve or test their JavaScript proficiency.

Personalize your quiz and earn a certificate with your name on it!
2. Onmouseover and onmouseout is a valid event in javascript

Explanation

The statement is true because onmouseover and onmouseout are valid event handlers in JavaScript. These events are triggered when the mouse pointer enters or exits an element on a webpage, allowing developers to perform specific actions or execute code in response to these events.

Submit
3. Testing

Explanation

The correct answer is "Click here" because the question asks for a suggestion based on the given options. Since all the options are "Do not click here" except for one, the only logical choice is to select "Click here" as the answer.

Submit
4. The function statement is not the only way to define a new function; you can definefunction dynamically using Function()constructor along with the newoperator. 

Explanation

The statement is true because in JavaScript, the Function() constructor can be used to define a new function dynamically. This allows for more flexibility in creating functions, as it is not limited to the traditional function statement syntax. The new operator is used in conjunction with the Function() constructor to create the function object.

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

The given code snippet includes a JavaScript function called "sayHello()" which uses the document.write() method to display the text "Hello there!" on the webpage. When the button is clicked, the function is called and the output "Hello there!" is displayed. Therefore, the correct answer is "when the button is clicked an output 'Hello there!' will be displayed".

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

Explanation

The correct answer is "document.write ("Hello world");". This is because the write() method of the document object is used to write content directly onto the document. In this example, the content "Hello world" is being written onto the document using the document.write() method.

Submit
7. When the page loads, it is  calledan event. When the user clicks a button, that click too is an event. 

Explanation

The given statement is true. When a page loads, it triggers an event known as "onload" event. This event is fired when the entire webpage including its content, images, and scripts have finished loading. Similarly, when a user clicks a button, it also triggers an event called "onclick" event. These events are essential for creating interactive webpages and allow developers to perform specific actions or execute code when certain events occur.

Submit
8. Using _______ statement is how you test for a specific condition.

Explanation

The "If" statement is used to test for a specific condition in programming. It allows the program to execute a certain block of code only if the condition is true. This statement is commonly used in decision-making processes, where different actions need to be taken based on different conditions.

Submit
9. How to create a Date object in JavaScript?

Explanation

To create a Date object in JavaScript, we use the syntax "dateObjectName = new Date([parameters])". This syntax initializes a new Date object and assigns it to the variable "dateObjectName". The optional "parameters" can be used to specify the date and time for the object.

Submit
10. Is it possible to nest functions in JavaScript?

Explanation

Yes, it is possible to nest functions in JavaScript. This means that we can define a function inside another function. The inner function will have access to the variables and scope of the outer function. This allows for the creation of more modular and organized code, as well as the ability to create private variables and functions that are only accessible within the outer function.

Submit
11. Methods are the functions that let the object do something or let something be done to it.

Explanation

This statement is true because methods in object-oriented programming are indeed functions that allow an object to perform certain actions or operations. These methods can be used to manipulate the object's data, interact with other objects, or perform any other necessary tasks. Methods provide the behavior or functionality of an object and allow it to respond to messages or requests. Therefore, the given answer is true.

Submit
12. Before we use a function, we need to define it first.

Explanation

This statement is true because in programming, before we can use a function, we must first define it. Defining a function involves specifying its name, parameters, and the actions it performs. Once a function is defined, we can then call or use it in our code to execute the actions specified within the function definition.

Submit
13. 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 the programmer to break down the code into smaller, manageable pieces, making it easier to read, understand, and maintain. By using functions, the programmer can avoid repetition and promote code reusability, improving the overall efficiency and organization of the program.

Submit
14. The most common way to definea 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 named or anonymous function in JavaScript. It is followed by the function name (optional) and a set of parentheses, which can contain parameters for the function. The function body is enclosed in curly braces, where the code to be executed is written. Using the "function" keyword is the standard and widely accepted method for defining functions in JavaScript.

Submit
15. What is the output of the given script?script language="javascript">function x(){document.write(2+5+"8");}</script>

Explanation

The given script defines a function called "x" that uses the document.write() method to output the result of the expression 2 + 5 + "8". In JavaScript, when a string is concatenated with a number, the number is converted to a string before concatenation. So, the expression evaluates to "7" + "8", which results in the string "78". Therefore, the output of the script is "78".

Submit
16. Objects are composed of attributes

Explanation

Objects are indeed composed of attributes. Attributes are the characteristics or properties that define an object. These attributes can include things like size, color, shape, and any other relevant information that describes the object. Therefore, it is correct to say that objects are composed of attributes.

Submit
17. Which of the following function of String object returns a string representing the specified object?

Explanation

The toString() function of the String object returns a string representing the specified object. This means that it converts any object into a string representation. In the given question, the other options (toLocaleUpperCase(), toUpperCase(), substring()) do not perform the same action of converting an object into a string. Hence, toString() is the correct answer.

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

Explanation

Inheritance is the correct answer because it allows a class to inherit properties and methods from another class, also known as the parent or base class. This enables the class to rely on the parent class for certain functionalities, reducing code duplication and promoting code reuse. Inheritance establishes an "is-a" relationship between classes, where the child class is a specialized version of the parent class.

Submit
19. What is mean by "this" keyword in javascript?

Explanation

The "this" keyword in JavaScript refers to the current object. It is commonly used within object methods to refer to the object itself. When a method is called using dot notation, the object before the dot is considered the current object and "this" can be used to access its properties and methods.

Submit
20. 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 is invoked. It allows access to the current object's properties and methods within its own scope.

Submit
21. The behaviour 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 contain the blueprint or definition of objects, and methods are functions or behaviors associated with those objects. Therefore, the behavior of instances of a class, including any methods they may have, is determined by the class itself.

Submit
22. 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" which takes a parameter "x" and returns the square of "x". It then immediately invokes this function with the argument 10. The result of this invocation is assigned to the variable "tensquared". Therefore, the code will successfully calculate the square of 10 and store it in the variable "tensquared".

Submit
23. When the page loads, it is  called an____

Explanation

When the page loads, it is called an event.

Submit
24. It is the capability to write one function or method that worksin a variety of different ways.

Explanation

Polymorphism is the correct answer because it refers to the capability of writing a function or method that can be used in different ways. In object-oriented programming, polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling them to be used interchangeably. This flexibility in functionality is a key aspect of polymorphism.

Submit
25. 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. The Function() constructor allows us to create a new function object dynamically at runtime. It takes arguments as the function parameters and the function body as a string. This syntax is commonly used when we need to create a function dynamically based on certain conditions or inputs.

Submit
26. A method is a function that creates and initializes an object

Explanation

A method is a function that creates and initializes an object. This statement is true because methods in object-oriented programming are functions that are associated with a particular class or object. They are responsible for creating and initializing instances of that class or object. Methods can perform various actions on the object, access its attributes, and modify its state. Therefore, it is correct to say that a method is a function that creates and initializes an object.

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

Explanation

The correct answer is that a function can take multiple parameters separated by a comma. This means that when defining a function, you can specify multiple variables that will be used as input when the function is called. This allows for flexibility and reusability in code, as different values can be passed to the function each time it is called.

Submit
28. 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 because the variable "i" in the for loop is declared using the "var" keyword, which has function scope. This means that when the functions in the array are called, they will all reference the same variable "i" with the value of 10, which is the last value assigned to "i" in the for loop.

Submit
29. JavaScript's interaction with HTML is handled through ___ that occur whenthe 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 actions or occurrences that happen in the browser, such as clicking a button, submitting a form, or scrolling a page. JavaScript can listen for these events and respond to them by executing code or performing certain actions. By using events, JavaScript can dynamically update the HTML content, validate user inputs, or trigger animations and effects on the webpage.

Submit
30. 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 number or a keyword. The other options, "123", "Exception", and "NaN", are all either numeric values or reserved keywords in programming. Therefore, "123xyz" stands out as the only value that is not a number or a keyword.

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

Explanation

The keyword "void" in JavaScript is used as a unary operator that appears before its single operand. It can be used with any type of operand. When "void" is used before an expression, it evaluates the expression and then returns undefined. This can be useful in certain situations, such as when you want to execute a function but do not need to use its return value.

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

Explanation

The correct answer is "alert()". This is an example of a JavaScript function because it is a built-in function in JavaScript that displays a dialog box with a message and an OK button. It is commonly used to show pop-up messages or notifications to the user.

Submit
33. 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 is used in object-oriented programming to allocate memory for an object and initialize its properties and methods. By using the "new" operator, we can create multiple instances of the same class, each with its own set of values and behaviors.

Submit
34. A JavaScript function should always have aReturn statement. 

Explanation

A JavaScript function does not always have to have a return statement. A return statement is used to specify the value that should be returned by the function. However, if a return statement is not included in a function, the function will still execute its code but will not return any value. So, it is not necessary for a JavaScript function to have a return statement.

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

Explanation

The correct answer is "var o= new Object;". This is because the code snippet is creating a new object using the Object constructor and assigning it to the variable "o". The syntax "new Object" is used to create a new instance of an object. The other options are incorrect because they either don't create a new object or have incorrect syntax.

Submit
36. Which of the following syntax is an example of properly declaring function

Explanation

not-available-via-ai

Submit
37. It is the capability to store related information, whether dataor methods, together in an object.

Explanation

Encapsulation refers to the concept of bundling related information, such as data and methods, together in an object. This allows for better organization and management of the code, as well as providing data protection by hiding the internal details of the object. Encapsulation helps to achieve data abstraction and modularity, making the code more maintainable and reusable.

Submit
38. 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 owner or container of the other object. The contained object can exist independently and can be shared among multiple containers. This allows for a flexible and modular design, where objects can be composed and combined to create more complex structures. Aggregation is often used to represent relationships between objects in object-oriented programming, where one object is composed of or contains other objects.

Submit
39. Inside which HTML element do we put the JavaScript?

Explanation

In HTML, we put JavaScript code inside the "script" element. This element is used to define or reference an external script file, or to embed JavaScript code directly within the HTML document. By placing the JavaScript inside the "script" element, the browser knows that it should interpret the content as JavaScript code and execute it accordingly.

Submit
40. 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 an object. It is called when an object of a class is created and it sets the initial values of the object's properties. Constructors are essential in object-oriented programming as they ensure that objects are properly initialized before they are used. In this context, a constructor is the correct answer as it fits the definition provided in the question.

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

Explanation

In JavaScript, functions do not necessarily return a value. While it is possible for a function to return a value using the return statement, it is not mandatory. If a function does not have a return statement, it will return undefined by default. Therefore, only a few functions in JavaScript actually return values by default.

Submit
42. 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. The propertyValue is assigned directly to the object's objectProperty without using the "new" keyword or parentheses.

Submit
43. Which of the following are capabilities of functions in JavaScript?

Explanation

Functions in JavaScript have the capability to accept parameters, which allows them to receive input values from the caller. This enables functions to perform specific actions or calculations based on the provided parameters. By accepting parameters, functions can be more flexible and reusable, as they can be used with different values each time they are called. Additionally, functions in JavaScript can also return a value, allowing them to produce an output that can be used by the caller or stored in a variable for further use.

Submit
44. The syntax for adding property is:ObjectName.objectProperty = new propertyValue; 

Explanation

The given statement is false because the syntax for adding a property is actually: ObjectName.propertyName = propertyValue. The "objectProperty" mentioned in the statement is not a valid syntax.

Submit
45. This is the most frequently used event type which occurs when a user clicks theleft button of his mouse

Explanation

The correct answer is onClick. This event type is the most frequently used when a user clicks the left button of their mouse.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

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

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 08, 2017
    Quiz Created by
    Ronnelagulto
Cancel
  • All
    All (45)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
JavaScript's interaction with HTML is handled through events that...
Onmouseover and onmouseout is a valid event in javascript
Testing
The function statement is not the only way to define a new function;...
What is the output of the following snippet:   ...
Which of the following is an example to show how to use thewrite()...
When the page loads, it is  calledan event. When the user clicks...
Using _______ statement is how you test for a specific condition.
How to create a Date object in JavaScript?
Is it possible to nest functions in JavaScript?
Methods are the functions that let the object do something or let...
Before we use a function, we need to define it first.
It is a group of reusable code which can be called anywhere in your...
The most common way to definea function in JavaScript is by using...
What is the output of the given script?script...
Objects are composed of attributes
Which of the following function of String object returns a string...
It is the capability of a class to rely upon another class (ornumber...
What is mean by "this" keyword in javascript?
The keyword or the property that you use to refer to an object through...
The behaviour of the instances present of a class inside a method is...
Consider the following code snippet : var tensquared = (function(x)...
When the page loads, it is  called an____
It is the capability to write one function or method that worksin a...
The follwing syntax is used to? <script...
A method is a function that creates and initializes an object
Which of the following statement about the function is true?
Consider the following code snippet :function constfuncs() ...
JavaScript's interaction with HTML is handled through ___ that...
Consider the following code snippet
It is is an important keyword in JavaScript which can be used as a...
Which of the following is an example of a javascript function?
The____ operator is used to create an instance of an object.
A JavaScript function should always have aReturn statement. 
For the below mentioned code snippet: var o = new Object(); The...
Which of the following syntax is an example of properly declaring...
It is the capability to store related information, whether dataor...
It is the capability to store one object inside another object.
Inside which HTML element do we put the JavaScript?
A _______is a function that creates and initializes an object.
Do functions in JavaScript necessarily return a value?
The syntax for adding a property to an object is:
Which of the following are capabilities of functions in JavaScript?
The syntax for adding property is:ObjectName.objectProperty = new...
This is the most frequently used event type which occurs when a user...
Alert!

Advertisement