JavaScript Quiz: MCQ Trivia Exam!

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 Gary Neslon
G
Gary Neslon
Community Contributor
Quizzes Created: 1 | Total Attempts: 403
Questions: 20 | Attempts: 403

SettingsSettingsSettings
JavaScript Quizzes & Trivia

Questions and Answers
  • 1. 

    Name two different ways to call a function.

    • A.

      When the function is stored in the JavaScript Folder

    • B.

      When it is invoked from JavaScript code

    • C.

      When an event occurs (when a user clicks a button)

    • D.

      When you book a hall for a private function

    Correct Answer(s)
    B. When it is invoked from JavaScript code
    C. When an event occurs (when a user clicks a button)
    Explanation
    The correct answer is "When it is invoked from JavaScript code" and "When an event occurs (when a user clicks a button)". These two ways refer to different ways of calling a function in JavaScript. The first way is by directly invoking the function from JavaScript code using its name followed by parentheses. The second way is by attaching the function as an event handler to an HTML element or DOM object, so that it is called when a specific event, such as a button click, occurs.

    Rate this question:

  • 2. 

    What would best describe the code below: var nums = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];

    • A.

      An array of strings

    • B.

      An array of integers

    • C.

      A variable

    • D.

      A list of numbers

    Correct Answer
    B. An array of integers
    Explanation
    The code provided initializes a variable called "nums" with an array of integers. The array contains the numbers 1, 2, 3, 4, 5, 6, 7, 8, and 9. Therefore, the correct answer is "An array of integers."

    Rate this question:

  • 3. 

    JavaScript code will load before the webpage if stored in the head tags.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    When JavaScript code is placed within the head tags of an HTML document, it will load before the webpage is fully rendered. This means that any JavaScript functions or actions specified in the code will be executed before the rest of the webpage content is displayed. This can be useful for situations where the JavaScript code needs to manipulate or interact with elements on the webpage as soon as possible. Placing JavaScript in the head tags can also ensure that any necessary scripts are loaded and ready to be used before the rest of the page is loaded.

    Rate this question:

  • 4. 

    It can be considered good practice to insert JavaScript code before the closing body ta, as this allows the HTML to load first

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Inserting JavaScript code before the closing body tag is considered good practice because it allows the HTML to load first. By placing the JavaScript code at the end of the body, it ensures that the HTML elements have been parsed and rendered by the browser before any JavaScript code is executed. This can improve the overall performance and user experience of the website, as it allows the page content to be displayed to the user more quickly. Additionally, it can prevent any potential issues or errors that may arise if the JavaScript code tries to manipulate HTML elements that have not yet been loaded.

    Rate this question:

  • 5. 

    When linking to an external JavaScript file what extension would the file have?

    • A.

      .javascript

    • B.

      .js

    • C.

      .java

    • D.

      .JSCRIPT

    Correct Answer
    B. .js
    Explanation
    When linking to an external JavaScript file, the file would have a .js extension. This is the standard file extension for JavaScript files, which allows the browser to recognize and interpret the code correctly. The .javascript, .java, and .JSCRIPT extensions are not commonly used for JavaScript files.

    Rate this question:

  • 6. 

    When calling a function you pass in ......

    Correct Answer
    arguments
    Explanation
    When calling a function, you pass in arguments. Arguments are the values or variables that are passed into a function when it is called. These arguments can be used within the function to perform certain operations or calculations. By passing in arguments, you can customize the behavior of the function and make it more flexible and reusable.

    Rate this question:

  • 7. 

    A user defined function or a built in function can have a list of.....

    • A.

      Arguments

    • B.

      Parameters

    • C.

      Functions

    • D.

      Variables

    Correct Answer
    B. Parameters
    Explanation
    A user-defined function or a built-in function can have a list of parameters. Parameters are variables that are used to pass values into a function. They allow the function to work with different values each time it is called. By specifying parameters, the function can be more flexible and reusable, as it can be used with different input values.

    Rate this question:

  • 8. 

    In the loop below when i equals 2 what color will be displayed in the console? var colours = [red, green, blue]; for(i = 0;  i < colours.length;  i++)  { console.log(colours[i]); }

    • A.

      Red

    • B.

      Blue

    • C.

      Green

    • D.

      None of the above

    Correct Answer
    B. Blue
    Explanation
    The given loop iterates over the array "colours" and prints each element to the console. Since the loop starts at index 0 and increments the value of "i" by 1 with each iteration, when "i" equals 2, the third element of the array will be printed, which is "blue".

    Rate this question:

  • 9. 

    In the code below what word describes each time the loop goes round? for(i = 0;  i < 10;  i++)  { console.log( i );

    • A.

      Interaction

    • B.

      Iteration

    • C.

      Individual

    • D.

      Interstellar

    Correct Answer
    B. Iteration
    Explanation
    The word that describes each time the loop goes round is "iteration". In this code, the loop is set to execute as long as the variable "i" is less than 10. Each time the loop iterates, the value of "i" is printed to the console. Therefore, "iteration" accurately describes the process of the loop going round and executing its code block repeatedly.

    Rate this question:

  • 10. 

    JavaScript is commonly known as...

    • A.

      Server Side Scripting Language

    • B.

      Client Side Scripting Language

    • C.

      Browser Scripting Language

    • D.

      Interactive Scripting Language

    Correct Answer
    B. Client Side Scripting Language
    Explanation
    JavaScript is commonly known as a client-side scripting language because it is primarily used to add interactivity and dynamic behavior to web pages on the client side, meaning it runs on the user's web browser. It allows for the manipulation of HTML elements, handling user events, and making asynchronous requests to the server. While JavaScript can also be used on the server side with platforms like Node.js, its main purpose and widespread usage is for client-side scripting.

    Rate this question:

  • 11. 

    JavaScript is used to...

    • A.

      Add interactivity to HTML pages

    • B.

      Add functionality to Server Side Pages

    • C.

      To style webpages

    • D.

      To create layout and structure for webpages

    Correct Answer
    A. Add interactivity to HTML pages
    Explanation
    JavaScript is used to add interactivity to HTML pages. It allows web developers to create dynamic and interactive elements on a webpage, such as form validation, image sliders, and interactive maps. By using JavaScript, users can interact with the webpage, input data, and receive responses or feedback in real-time. This makes the webpage more engaging and user-friendly. JavaScript is primarily a client-side scripting language, meaning it runs on the user's web browser rather than the server, making it an essential tool for enhancing the functionality and user experience of HTML pages.

    Rate this question:

  • 12. 

    What are the variables used for?

    • A.

      Storing integers for manipulating in code

    • B.

      Storing operators for manipulating in code

    • C.

      Storing methods for manipulating in code

    • D.

      Storing Strings for manipulating in code

    Correct Answer(s)
    A. Storing integers for manipulating in code
    D. Storing Strings for manipulating in code
    Explanation
    Variables are used for storing different types of data in code. In this case, the variables are used for storing integers and strings for manipulation in the code. Integers can be used for mathematical calculations and storing numerical values, while strings are used for storing text or characters. These variables can be manipulated and used in various ways within the code to perform different operations or tasks.

    Rate this question:

  • 13. 

    When joining 2 strings together in JavaScript this is known as?

    • A.

      Concave

    • B.

      Concatenation

    • C.

      Convexity

    • D.

      Convulsion

    Correct Answer
    B. Concatenation
    Explanation
    Concatenation is the correct answer because it refers to the process of combining two or more strings together in JavaScript. It involves joining the characters or elements of one string to the end of another string, resulting in a new string that contains the combined values. This term is commonly used in programming to describe the action of merging strings.

    Rate this question:

  • 14. 

    If a variable is created inside a function the variable scope would be known as...

    • A.

      Global

    • B.

      Cosmic

    • C.

      Local

    • D.

      Familiar

    Correct Answer
    C. Local
    Explanation
    When a variable is created inside a function, its scope is limited to that specific function. This means that the variable can only be accessed and used within that function. This type of scope is known as "local" because it is restricted to a specific portion of the code. Local variables are useful for storing temporary or intermediate values that are only needed within a particular function. They are not accessible outside of the function, which helps to prevent naming conflicts and keeps the code organized.

    Rate this question:

  • 15. 

    A Global variable can be accessed from any part of your program.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    A global variable is a variable that is defined outside of any function and can be accessed from any part of the program. This means that it is not limited to a specific scope and can be used in multiple functions or modules. Therefore, the statement "A Global variable can be accessed from any part of your program" is true.

    Rate this question:

  • 16. 

    Which part of the following code is the conditional statement? if ( x > 5)  { console.log("Good Morning"); }else{"Goodnight"}

    • A.

      Else{"Goodnight")

    • B.

      ( x > 5)

    • C.

      Document.write

    • D.

      If

    Correct Answer
    B. ( x > 5)
    Explanation
    The conditional statement in the given code is "( x > 5)". This is the part of the code that is being evaluated to determine whether the condition is true or false. If the condition is true, the code inside the if block will be executed, which in this case is "console.log("Good Morning")". If the condition is false, the code inside the else block will be executed, which is missing in the given code but should be "console.log("Goodnight")".

    Rate this question:

  • 17. 

    When Developing Software - check the boxes that would be considered good practice.

    • A.

      Appropriate naming of variables

    • B.

      Appropriate description/naming of functions

    • C.

      Commenting all logic in the code

    • D.

      Make sure you use a cool theme

    Correct Answer(s)
    A. Appropriate naming of variables
    B. Appropriate description/naming of functions
    C. Commenting all logic in the code
    Explanation
    Good software development practices include appropriate naming of variables, as it improves code readability and makes it easier to understand the purpose of each variable. Appropriate description/naming of functions is also important as it helps other developers understand the functionality of each function. Commenting all logic in the code is crucial for future reference and collaboration, as it provides explanations and context for the code. However, using a cool theme is not considered a good practice in software development as it is unrelated to the functionality and quality of the software.

    Rate this question:

  • 18. 

    Which one of the choices below is considered a selection construct in programming?

    • A.

      While

    • B.

      If..maybe

    • C.

      If...else

    • D.

      Var array

    Correct Answer
    C. If...else
    Explanation
    The choice "if...else" is considered a selection construct in programming because it allows the program to make decisions based on certain conditions. With the "if" statement, the program checks if a condition is true and executes a block of code if it is. If the condition is false, the program can then execute an alternative block of code using the "else" statement. This selection construct is commonly used to control the flow of the program based on different conditions.

    Rate this question:

  • 19. 

    Which Animal will the if statement display in the alert box? var animals = [ "Dog", "Cat", "Lion", "Bird", "Duck" ]; for( i = 0; i < animals.length; i++ ) { if( i === 4) { alert("The animal name is " + animals[ i ] ); }else{console.log(animals[ i ]); } }

    • A.

      Cat

    • B.

      Lion

    • C.

      Bird

    • D.

      Duck

    • E.

      Dog

    Correct Answer
    D. Duck
    Explanation
    The if statement in the code checks if the value of i is equal to 4. When i is equal to 4, the alert box will display "The animal name is Duck". Therefore, the correct answer is Duck.

    Rate this question:

  • 20. 

    Will the following condition return true OR false ?var x = 6;if( x >= 6 )  {console.log("Yes " +  x + "  is a Great Number")}

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The condition in the given code is checking if the value of variable x is greater than or equal to 6. Since the value of x is 6, which is equal to 6, the condition will evaluate to true. Therefore, the code inside the if statement will be executed and the message "Yes 6 is a Great Number" will be printed.

    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
  • May 03, 2017
    Quiz Created by
    Gary Neslon
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.