JavaScript Trivia Exam: 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: 569
Questions: 45 | Attempts: 168

SettingsSettingsSettings
JavaScript Quizzes & Trivia


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

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

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

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

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

    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;". 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.

    Rate this question:

  • 7. 

    The most common way to definea 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 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.

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

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

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

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

    Rate this question:

  • 12. 

    The behaviour 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 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.

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

    Rate this question:

  • 14. 

    JavaScript's interaction with HTML is handled through ___ that occur whenthe 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 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.

    Rate this question:

  • 15. 

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

    • A.

      OnSubmit

    • B.

      Onmouseover

    • C.

      OnClick

    • D.

      All of the given

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

    Rate this question:

  • 16. 

    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.

    • A.

      Return

    • B.

      Void

    • C.

      Function

    • D.

      Script

    Correct Answer
    B. Void
    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.

    Rate this question:

  • 17. 

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

    • A.

      Encapsulation

    • B.

      Aggregation

    • C.

      Inheritance

    • D.

      Polymorphism

    Correct Answer
    A. Encapsulation
    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.

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

    Rate this question:

  • 19. 

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

    • A.

      Polymorphism

    • B.

      Encapsulation

    • C.

      Inheritance

    • D.

      Aggregation

    Correct Answer
    A. Polymorphism
    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.

    Rate this question:

  • 20. 

    It is the capability of a class to rely upon another class (ornumber 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 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.

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

    Rate this question:

  • 22. 

    Which of the following is an example to show how to use thewrite() method of 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 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.

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

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

    Rate this question:

  • 25. 

    Which of the following syntax is an example of properly declaring 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()
  • 26. 

    When the page loads, it is  called an____

    • A.

      Event

    • B.

      Function

    • C.

      Script

    • D.

      Form

    Correct Answer
    A. Event
    Explanation
    When the page loads, it is called an event.

    Rate this question:

  • 27. 

    Which of the following are capabilities of functions in JavaScript?

    • A.

      Return a value

    • B.

      Accept parameters and Return a value

    • C.

      Accept parameters

    • D.

      None of the above

    Correct Answer
    C. Accept parameters
    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.

    Rate this question:

  • 28. 

    Inside which HTML element do we put the JavaScript?

    • A.

      Js

    • B.

      Scripting

    • C.

      Script

    • D.

      Javascript

    Correct Answer
    C. Script
    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.

    Rate this question:

  • 29. 

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

    • A.

      Select

    • B.

      If

    • C.

      Switch

    • D.

      For

    Correct Answer
    B. If
    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.

    Rate this question:

  • 30. 

    How to create a Date object in JavaScript?

    • A.

      DateObjectName = new Date([parameters])

    • B.

      DateObjectName.new Date([parameters])

    • C.

      DateObjectName := new Date([parameters])

    • D.

      DateObjectName Date([parameters])

    Correct Answer
    A. DateObjectName = new Date([parameters])
    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.

    Rate this question:

  • 31. 

    Is it possible to nest functions in JavaScript?

    • A.

      True

    • B.

      False

    • C.

      -ERROR do not click-

    • D.

      -ERROR do not click-

    Correct Answer
    A. True
    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.

    Rate this question:

  • 32. 

    What is mean by "this" keyword in javascript?

    • A.

      It refers current object

    • B.

      It refers previous object

    • C.

      It is variable which contains value

    • D.

      None of the above

    Correct Answer
    A. It refers current object
    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.

    Rate this question:

  • 33. 

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

    • A.

      258

    • B.

      Error

    • C.

      7

    • D.

      78

    Correct Answer
    D. 78
    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".

    Rate this question:

  • 34. 

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

    • A.

      ToLocaleUpperCase()

    • B.

      ToUpperCase()

    • C.

      ToString()

    • D.

      Substring()

    Correct Answer
    C. ToString()
    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.

    Rate this question:

  • 35. 

    JavaScript's interaction with HTML is handled through events that occur whenthe user or the  browser manipulates a page 

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 36. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 37. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 38. 

    A JavaScript function should always have aReturn statement. 

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    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.

    Rate this question:

  • 39. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 40. 

    Onmouseover and onmouseout is a valid event in javascript

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 41. 

    Objects are composed of attributes

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 42. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    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.

    Rate this question:

  • 43. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 44. 

    A method is a function that creates and initializes an object

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 45. 

    Testing

    • A.

      Click here

    • B.

      Do not click here

    • C.

      Do not click here

    • D.

      Do not click here

    Correct Answer
    A. Click here
    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.

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.