Loading...

Go Back

Finish
Go Back Course Outline

JavaScript Full Course


Quiz

JavaScript Quiz

1. What is the correct syntax to print "Hello World" in JavaScript?

console.print("Hello World");
print("Hello World");
console.log("Hello World");
log("Hello World");

2. Which of the following is NOT a JavaScript data type?

String
Boolean
Integer
Object

3. How do you create a function in JavaScript?

function:myFunction() {}
function myFunction() {}
def myFunction() {}
function = myFunction() {}

4. What will the following code output?
console.log(typeof NaN);

"undefined"
"object"
"number"
"NaN"

5. Which of these methods is used to add elements to an array in JavaScript?

push()
append()
add()
insert()

6. What is the correct way to declare a constant in JavaScript?

const myVar;
let myVar;
var myVar;
constant myVar;

7. Which of the following is the correct way to write an if statement in JavaScript?

if x = 5
if (x == 5)
if (x = 5)
if x == 5

8. What will the following code output?
console.log(0 == '0');

true
false
undefined
NaN

9. Which event is triggered when the user clicks on a button?

click
mouseover
submit
change

10. How do you declare an array in JavaScript?

var myArray = [];
var myArray = {};
var myArray = () {};
var myArray = "";

11. Which method is used to remove the last element of an array?

pop()
shift()
unshift()
remove()

12. Which of these is the correct way to add an event listener in JavaScript?

element.addEventListener('click', function);
element.addEvent('click', function);
element.addListener('click', function);
element.onClick('click', function);

13. What is the correct syntax for a while loop in JavaScript?

while (i <= 10) {}
while i <= 10 {}
loop (i <= 10) {}
do while (i <= 10) {}

14. Which JavaScript function is used to parse a JSON string into a JavaScript object?

JSON.parse()
JSON.stringify()
parseJSON()
stringifyJSON()

15. What is the correct way to concatenate two arrays in JavaScript?

array1.concat(array2);
array1 + array2;
array1.append(array2);
array1.push(array2);

16. Which of these is the correct way to handle asynchronous JavaScript?

Callbacks
Promises
async/await
All of the above

17. What does the `this` keyword refer to in JavaScript?

The global object
The current object
The function scope
All of the above

18. How do you define a class in JavaScript?

class MyClass {}
function MyClass() {}
var MyClass = {};
object MyClass {}

19. What is the default value of a JavaScript variable?

null
undefined
0
false

20. Which method is used to change the content of an HTML element in JavaScript?

innerHTML
textContent
setContent
content

21. Which method is used to remove an element from the DOM?

removeChild()
deleteNode()
destroyNode()
removeElement()

22. Which operator is used to compare two values for equality without type conversion in JavaScript?

==
===
!=
!==

23. What will the following code output?
console.log(2 + '2');

4
22
"4"
"22"

24. How can you check if an object is an array in JavaScript?

Array.isArray(object);
object.isArray();
object instanceof Array;
All of the above

25. How do you prevent a form from submitting in JavaScript?

event.preventDefault();
return false;
event.stopPropagation();
Both a and b

26. Which of the following is a false statement about JavaScript?

JavaScript is a loosely-typed language.
Variables are always declared using 'var'.
JavaScript supports object-oriented programming.
JavaScript supports functional programming.

27. What is a promise in JavaScript?

A way to handle errors in code.
An object representing the eventual completion or failure of an asynchronous operation.
A way to store functions.
A function that always returns true.

28. What is the purpose of the `async` keyword in JavaScript?

To define a function that always returns a promise.
To make a function run asynchronously without blocking the execution of other code.
To define a function that runs synchronously.
None of the above

29. Which of the following is NOT a valid variable name in JavaScript?

_myVar
myVar
2myVar
$myVar

30. What does the `setTimeout()` function do in JavaScript?

Executes a function after a specified delay.
Executes a function immediately.
Cancels a function.
Pauses the execution of the code.
Go Back

Finish