JavaScript Test: Ultimate Trivia 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 Mohamed Anas
M
Mohamed Anas
Community Contributor
Quizzes Created: 1 | Total Attempts: 815
Questions: 34 | Attempts: 815

SettingsSettingsSettings
JavaScript Test: Ultimate Trivia Quiz! - Quiz

.


Questions and Answers
  • 1. 

    Given x = new Date(), how do you represent x as a String in universal time (time zone +0000)?

    • A.

      X.getUTC();

    • B.

      X.getUTCDate();

    • C.

      X.toUTCString();

    Correct Answer
    C. X.toUTCString();
    Explanation
    The correct answer is x.toUTCString() because the toUTCString() method converts the date to a string representation in universal time (time zone +0000). This method returns a string that represents the date and time in the format "Thu, 01 Jan 1970 00:00:00 GMT".

    Rate this question:

  • 2. 

    Where the < script > tag can be used

    • A.

      In the < head > tag

    • B.

      In the < body > tag

    • C.

      Both < head > and < body > tags

    Correct Answer
    C. Both < head > and < body > tags
    Explanation
    The tag can be used in both the and tags of an HTML document. Placing it in the tag allows the script to be loaded and executed before the content of the webpage is displayed. This is useful for scripts that need to be run before the page is rendered. On the other hand, placing the tag in the tag allows the script to be loaded and executed after the content of the webpage is displayed. This is useful for scripts that manipulate or interact with the content of the webpage.

    Rate this question:

  • 3. 

    What does JSON stand for?

    • A.

      JavaScript Oriented Notation

    • B.

      JavaScript Object Notation

    • C.

      JavaScript Online Notation

    Correct Answer
    B. JavaScript Object Notation
    Explanation
    JSON stands for JavaScript Object Notation. It is a lightweight data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. It is primarily used to transmit data between a server and web application, as an alternative to XML. JSON uses key-value pairs and supports arrays, making it a popular choice for representing structured data.

    Rate this question:

  • 4. 

    Given the following, what is the value of x? var x = typeof "abc";

    • A.

      Abc

    • B.

      String

    • C.

      Undefined

    • D.

      Error

    Correct Answer
    B. String
    Explanation
    The value of x is "string" because the typeof operator returns the data type of a variable or expression. In this case, "abc" is a string, so the typeof "abc" is "string".

    Rate this question:

  • 5. 

    Variable x has a value of 5. Variable y has a value of 7 x < 7 && y > 6

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The expression "x < 7 && y > 6" is evaluating two conditions using logical AND operator. The first condition "x < 7" is true because the value of x is 5 which is less than 7. The second condition "y > 6" is also true because the value of y is 7 which is greater than 6. Since both conditions are true, the overall expression evaluates to true. Therefore, the correct answer is True.

    Rate this question:

  • 6. 

    Is javascript case sensitive ?

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    JavaScript is indeed case sensitive. This means that it distinguishes between uppercase and lowercase letters. For example, "variable" and "Variable" would be considered as two different variables in JavaScript. This is important to keep in mind when writing code, as using incorrect casing can lead to errors or unexpected behavior in the program.

    Rate this question:

  • 7. 

    To convert string to number, which function do we use ?

    • A.

      ParseNumber

    • B.

      ParseString

    • C.

      ParseInt

    • D.

      ParseDouble

    Correct Answer
    C. ParseInt
    Explanation
    The parseInt function is used to convert a string to an integer number. It parses the string and returns an integer value. This function is commonly used when we need to perform mathematical operations or comparisons on a string that represents a number.

    Rate this question:

  • 8. 

    In javascript, is it required having semi-colon " ; " at the end of the statement ?

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    In JavaScript, it is not required to have a semi-colon at the end of every statement. JavaScript has automatic semi-colon insertion, which means that the interpreter will insert a semi-colon at the end of a statement if it is missing. However, it is considered a best practice to include semi-colons in order to avoid potential issues and make the code more readable.

    Rate this question:

  • 9. 

    How do you check what the type of a value in variable x is?

    • A.

      Gettype(x)

    • B.

      Typeof(x)

    • C.

      Object.type(x)

    • D.

      X.type

    Correct Answer
    B. Typeof(x)
    Explanation
    The typeof() function is used to check the type of a value in JavaScript. In this case, typeof(x) would return the type of the value stored in the variable x. The other options, gettype(x), Object.type(x), and x.type, are not valid JavaScript syntax for checking the type of a value.

    Rate this question:

  • 10. 

    What is the value of the following express: 8 % 3

    • A.

      5

    • B.

      2

    • C.

      24

    • D.

      NaN

    Correct Answer
    B. 2
    Explanation
    The expression 8 % 3 calculates the remainder when 8 is divided by 3. In this case, 8 divided by 3 is equal to 2 with a remainder of 2. Therefore, the value of the expression is 2.

    Rate this question:

  • 11. 

    You need to update the content of a <div> using the following code, complete the missing part <div id="myDiv"></div> <script> document.getElementById('myDiv').MISSING_PART = "new content" </script>

    • A.

      Innerhtml

    • B.

      InnerHtml

    • C.

      InnterHtml

    • D.

      InnerHTML

    Correct Answer
    D. InnerHTML
    Explanation
    The missing part in the code should be "innerHTML". The correct code should be:

    document.getElementById('myDiv').innerHTML = "new content"

    This code will update the content of the element with the id "myDiv" by setting its innerHTML property to "new content".

    Rate this question:

  • 12. 

    What's the output of the following code var name = 'John', age = 20 console.log(`Hi, my name is ${name.toUpperCase()} and I'm ${++age} years old`)

    • A.

      Hi, my name is John and I'm 20 years old

    • B.

      Hi, my name is John and I'm 21 years old

    • C.

      Hi, my name is JOHN and I'm 20 years old

    • D.

      Hi, my name is JOHN and I'm 21 years old

    Correct Answer
    D. Hi, my name is JOHN and I'm 21 years old
    Explanation
    The code uses template literals to concatenate the variables `name` and `age` into a string. `name.toUpperCase()` converts the value of `name` to uppercase, resulting in "JOHN". `++age` increments the value of `age` by 1, resulting in 21. Therefore, the output is "Hi, my name is JOHN and I'm 21 years old".

    Rate this question:

  • 13. 

    How to access the current element using DOM <input type="radio" name="gender" value="Male">

    • A.

      Document.getElementById

    • B.

      Document.getElementByName

    • C.

      Document.getElementsByName

    • D.

      Document.getElement

    Correct Answer
    C. Document.getElementsByName
    Explanation
    The correct answer is document.getElementsByName. This method allows you to access elements by their name attribute. In this case, if you want to access the current element of the radio buttons with the name "gender", you can use this method to retrieve all the elements with that name and then loop through them to find the current one.

    Rate this question:

  • 14. 

    Which of these is not a logical operator?

    • A.

      !

    • B.

      &

    • C.

      &&

    • D.

      ||

    Correct Answer
    B. &
    Explanation
    The correct answer is "&". The logical operators in programming are used to perform logical operations on boolean values. The "!" operator is the logical NOT operator, which negates the value of a boolean expression. The "&" operator is the bitwise AND operator, not a logical operator. The "&&" operator is the logical AND operator, which returns true if both operands are true. The "||" operator is the logical OR operator, which returns true if at least one of the operands is true.

    Rate this question:

  • 15. 

    What is the value of the variable a? var a = "cat".length * 2;

    • A.

      3

    • B.

      6

    • C.

      0

    • D.

      1

    Correct Answer
    B. 6
    Explanation
    The value of the variable "a" is 6. This is because the expression "cat".length returns the length of the string "cat", which is 3. Multiplying 3 by 2 gives us the value of 6 for the variable "a".

    Rate this question:

  • 16. 

    What is the value of x ? var a = false; var x = a ? “A” : “B”;

    • A.

      Undefined

    • B.

      True

    • C.

      "A"

    • D.

      "B"

    Correct Answer
    D. "B"
    Explanation
    The value of x is "B" because the variable a is assigned the value false. In the ternary operator, if the condition (a) is true, the value "A" is assigned to x, but if the condition is false, the value "B" is assigned to x. Since a is false, the value "B" is assigned to x.

    Rate this question:

  • 17. 

    How would one declare a string variable?

    • A.

      Var name = "John"

    • B.

      Var names = "7"

    • C.

      Var firstname = new String("John")

    • D.

      Any of these

    Correct Answer
    D. Any of these
    Explanation
    The correct answer is "Any of these" because all three options demonstrate valid ways to declare a string variable in JavaScript. The first option assigns a string value directly to the variable "name", the second option assigns a string value to the variable "names", and the third option creates a new String object with the value "John" and assigns it to the variable "firstname". Therefore, any of these options can be used to declare a string variable.

    Rate this question:

  • 18. 

    Dvising a number by zero in JavaScript returns

    • A.

      Error with exception

    • B.

      NaN

    • C.

      Infinity

    Correct Answer
    C. Infinity
    Explanation
    When dividing a number by zero in JavaScript, it returns "Infinity". This is because dividing any number by zero is mathematically undefined and considered to be an infinitely large value. Therefore, JavaScript represents this result as "Infinity" to indicate that the division operation is not possible and the result is an infinitely large value.

    Rate this question:

  • 19. 

    How do you round the number 11.25, to the nearest whole number?

    • A.

      Math.round

    • B.

      Math.rnd

    • C.

      Round

    • D.

      Rnd

    Correct Answer
    A. Math.round
    Explanation
    To round the number 11.25 to the nearest whole number, you can use the Math.round function. This function rounds a number to the nearest integer. In this case, 11.25 is closer to 11 than to 12, so Math.round(11.25) will return 11.

    Rate this question:

  • 20. 

    What is the value of "b" var a = "A"; var b = a.concat("B");

    • A.

      ["A", "B"]

    • B.

      "AB"

    • C.

      "A"

    • D.

      "B"

    Correct Answer
    B. "AB"
    Explanation
    The value of "b" is "AB" because the concat() method is used to concatenate two strings together. In this case, the variable "a" is the string "A" and "B" is being concatenated to it, resulting in the string "AB".

    Rate this question:

  • 21. 

    Which event fires whenever a control loses focus?

    • A.

      On click

    • B.

      On move

    • C.

      On keydown

    • D.

      On blur

    Correct Answer
    D. On blur
    Explanation
    The "on blur" event fires whenever a control loses focus. This means that when a user clicks outside of the control or tabs to another element, the "on blur" event will be triggered. This event is commonly used to perform actions or validations when the user finishes interacting with a specific control, such as saving the entered data or checking for input errors.

    Rate this question:

  • 22. 

    Which of the following is the equivalent of the following snippet if (a) { x = b; } else { x = c; }

    • A.

      X = a : b ? c

    • B.

      X = a ? b : c

    • C.

      X = a ? b , c

    • D.

      X = a ? b || c

    Correct Answer
    B. X = a ? b : c
    Explanation
    The correct answer is "x = a ? b : c". This is the equivalent of the given snippet because it uses the ternary operator "? :" which is a shorthand for an if-else statement. It checks the condition "a", and if it is true, assigns the value of "b" to "x", otherwise assigns the value of "c" to "x".

    Rate this question:

  • 23. 

    Which of the following events is used to handle the user click action

    • A.

      Click

    • B.

      Clicked

    • C.

      Onclick

    Correct Answer
    C. Onclick
    Explanation
    The event "onclick" is used to handle the user click action. This event is triggered when the user clicks on an element, such as a button or a link, on a webpage. It allows developers to define a specific action or behavior to be executed when the user interacts with that element by clicking on it.

    Rate this question:

  • 24. 

    Which message does the following log to the console? bar(); function bar() { console.log('bar'); }

    • A.

      Undefined

    • B.

      TypeError

    • C.

      SyntaxError

    • D.

      "bar"

    Correct Answer
    D. "bar"
    Explanation
    The message that is logged to the console is "bar". This is because the function bar is called before it is defined, which is allowed in JavaScript. So when the function is called, it logs the string "bar" to the console.

    Rate this question:

  • 25. 

    What is the value of x? var x = '1'+2+3;

    • A.

      6

    • B.

      15

    • C.

      "123"

    • D.

      The statement generates an error

    Correct Answer
    C. "123"
    Explanation
    The value of x is "123" because the expression is evaluated from left to right. The first operand is a string "1", so the following operands are concatenated as strings. Therefore, 2 and 3 are also treated as strings and concatenated to "1" to form "123".

    Rate this question:

  • 26. 

    You have to change the background color of the page programmatically, which of the following instructions is correct ?

    • A.

      Document.body.background = 'red'

    • B.

      Document.body.color = 'red'

    • C.

      Document.body.style.background = 'red'

    • D.

      Document.body.style.color = 'red'

    Correct Answer
    C. Document.body.style.background = 'red'
    Explanation
    The correct answer is document.body.style.background = 'red'. This is because the style property allows you to access and modify the CSS properties of an element, including the background color. By setting the background property to 'red', you can change the background color of the page programmatically. The other options are incorrect because they either modify the wrong property (body.background, body.color) or use the wrong syntax (missing the style property).

    Rate this question:

  • 27. 

    What is the value of variable a var a = 3; var b = 2; var c = a; var a = b = c = 1;

    • A.

      3

    • B.

      2

    • C.

      1

    • D.

      Error

    Correct Answer
    C. 1
    Explanation
    The value of variable a is 1 because the code assigns the value of 1 to variables b, c, and a in that order. Therefore, the final value assigned to variable a is 1.

    Rate this question:

  • 28. 

    What is the value of the variable foo ? var foo = 10 + parseInt("20 bar 30");

    • A.

      30

    • B.

      NaN

    • C.

      "1020 bar 30"

    • D.

      60

    Correct Answer
    A. 30
    Explanation
    The value of the variable foo is 30. In the given code, the parseInt() function is used to convert the string "20 bar 30" into an integer. However, since the string contains non-numeric characters, the parseInt() function will only consider the numeric characters at the beginning of the string. Therefore, it will convert "20" into the number 20. The addition operation then adds 10 to 20, resulting in 30.

    Rate this question:

  • 29. 

    What would the code below return Math.min() < Math.max()

    • A.

      Undefined

    • B.

      False

    • C.

      Null

    • D.

      True

    Correct Answer
    B. False
    Explanation
    The code is comparing the result of the Math.min() function with the result of the Math.max() function. Since no arguments are provided to these functions, they will return positive or negative infinity. In JavaScript, positive infinity is greater than negative infinity, so the comparison Math.min() < Math.max() will evaluate to false. Therefore, the code will return false.

    Rate this question:

  • 30. 

    Evaluate the following: undefined + 2

    • A.

      Type Error

    • B.

      NaN

    • C.

      Undefined

    • D.

      2

    Correct Answer
    B. NaN
    Explanation
    When you try to perform addition with undefined and a number (in this case, 2), JavaScript treats undefined as NaN (Not a Number). Therefore, the result of undefined + 2 is NaN.

    Rate this question:

  • 31. 

    Within innerHTML, can you create HTML markup content and append it to the page

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
    Explanation
    Yes, within innerHTML, you can create HTML markup content and append it to the page. The innerHTML property allows you to manipulate the HTML content of an element. By setting the innerHTML property of an element, you can add HTML markup content, such as tags, attributes, and text, to that element. This allows you to dynamically generate and insert HTML content into the page.

    Rate this question:

  • 32. 

    To get value from user input we use which box ?

    • A.

      Confirm

    • B.

      Prompt

    • C.

      Alert

    • D.

      None of the above

    Correct Answer
    B. Prompt
    Explanation
    The correct answer is "Prompt" because the prompt box is used to get a value from the user. It displays a dialog box with a message and an input field where the user can enter a value. This value can then be used in the program for further processing or manipulation. The other options, Confirm and Alert, are used for displaying messages to the user but do not allow for user input. "None of the above" is not the correct answer as the prompt box is specifically designed for getting user input.

    Rate this question:

  • 33. 

    In do-while .. while with condition required ';' at the end of ()

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    In a do-while loop, the condition is placed inside the parentheses after the keyword "while". It does not require a semicolon at the end of the parentheses. Therefore, the statement "In do-while .. while with condition required ';' at the end of ()" is false.

    Rate this question:

  • 34. 

    Where do we start a javascript code ?

    • A.

      In the < javascript > tag

    • B.

      In the < code > tag

    • C.

      In the < script > tag

    • D.

      None of the above

    Correct Answer
    C. In the < script > tag
    Explanation
    In JavaScript, we start the code by writing it within the tag. This tag is used to define a client-side script, and it is placed within the HTML document. The JavaScript code written within the tag will be executed by the browser when the webpage loads. The other options mentioned, such as tag and tag, are not valid for starting a JavaScript code.

    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
  • Aug 28, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jul 20, 2018
    Quiz Created by
    Mohamed Anas
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.