JavaScript Test: Ultimate Trivia 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 Mohamed Anas
M
Mohamed Anas
Community Contributor
Quizzes Created: 1 | Total Attempts: 828
| Attempts: 828 | Questions: 34
Please wait...
Question 1 / 34
0 %
0/100
Score 0/100
1. Is javascript case sensitive ?

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.

Submit
Please wait...
About This Quiz
JavaScript Test: Ultimate Trivia Quiz! - Quiz

Dive into the JavaScript Test: Ultimate Trivia Quiz! Challenge your understanding of JavaScript fundamentals, including operations, date handling, JSON, and DOM manipulation. Perfect for learners looking to test... see moretheir knowledge and sharpen their coding skills. see less

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

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.

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

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.

Submit
4. What does JSON stand for?

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.

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

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.

Submit
6. Where the < script > tag can be used

Explanation

The

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

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

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

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

Submit
9. Where do we start a javascript code ?

Explanation

In JavaScript, we start the code by writing it within the

Submit
10. What is the value of the following express: 8 % 3

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.

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

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.

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

Explanation

The expression "x 6" is evaluating two conditions using logical AND operator. The first condition "x 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.

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

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

Submit
14. 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`)

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

Submit
15. Which of these is not a logical operator?

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.

Submit
16. Which of the following is the equivalent of the following snippet
if (a) { x = b; } else { x = 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".

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

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

Submit
18. How would one declare a string variable?

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.

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

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.

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

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".
Submit
21. To get value from user input we use which box ?

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.

Submit
22. What is the value of x ?
var a = false;
var x = a ? "A" : "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.

Submit
23. Which event fires whenever a control loses focus?

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.

Submit
24. Which message does the following log to the console?
bar(); 
function bar() { console.log('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.

Submit
25. What is the value of variable a
var a = 3; var b = 2; var c = a; var a = b = 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.

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

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.

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

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

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

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

Submit
29. Dvising a number by zero in JavaScript returns

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.

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

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.

Submit
31. Evaluate the following:
undefined + 2

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.

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

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.

Submit
33. What is the value of the variable foo ?
var foo = 10 + parseInt("20 bar 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.

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

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

Submit
View My Results

Quiz Review Timeline (Updated): Aug 28, 2023 +

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
Cancel
  • All
    All (34)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Is javascript case sensitive ?
How do you round the number 11.25, to the nearest whole number?
Which of the following events is used to handle the user click action
What does JSON stand for?
Within innerHTML, can you create HTML markup content and append it to...
Where the < script > tag can be used
Given the following, what is the value of x? var x = typeof "abc";
What is the value of the variable a? ...
Where do we start a javascript code ?
What is the value of the following express: 8 % 3
How do you check what the type of a value in variable x is?
Variable x has a value of 5. Variable y has a value of 7 ...
What is the value of "b" ...
What's the output of the following code ...
Which of these is not a logical operator?
Which of the following is the equivalent of the following snippet ...
You have to change the background color of the page programmatically,...
How would one declare a string variable?
To convert string to number, which function do we use ?
You need to update the content of a <div> using the following...
To get value from user input we use which box ?
What is the value of x ? var a = false; var x = a ? "A" : "B";
Which event fires whenever a control loses focus?
Which message does the following log to the console? ...
What is the value of variable a ...
In javascript, is it required having semi-colon " ; " at the...
Given x = new Date(), how do you represent x as a String in universal...
What is the value of x? var x = '1'+2+3;
Dvising a number by zero in JavaScript returns
In do-while .. while with condition required ';' at the end of...
Evaluate the following: undefined + 2
How to access the current element using DOM ...
What is the value of the variable foo ? ...
What would the code below return Math.min() < Math.max()
Alert!

Advertisement