JavaScript Fundamentals Quiz

Test your understanding of JavaScript concepts

Question 1 of 20
Score: 0 / 0
JavaScript in HTML

In what order will these console.log messages appear?

<html> <head> <script>console.log("Script A");</script> </head> <body> <h1>My Website</h1> <script>console.log("Script B");</script> <p>Content here</p> <script>console.log("Script C");</script> </body> </html>
JavaScript in HTML

Which JavaScript inclusion method is best for a large project with multiple pages?

Variables

Complete the variable declaration for a constant school name:

Declare a constant variable named "schoolName" with the value "JavaScript Academy":

Data Types

What is the data type of: [1, 2, 3, 4]?

Variables

Predict the output:

let firstName = "Alice"; let lastName = "Johnson"; console.log(firstName + " " + lastName);
Functions

What will this function return when called with calculateGrade(85)?

function calculateGrade(score) { if (score >= 90) { return "A"; } else if (score >= 80) { return "B"; } else { return "C"; } }
Functions

Write a function declaration that takes two numbers and returns their sum:

Control Structures

What will this code output?

let temperature = 25; if (temperature > 30) { console.log("Hot"); } else if (temperature > 20) { console.log("Warm"); } else { console.log("Cold"); }
Loops

How many times will this loop run?

for (let i = 0; i < 4; i++) { console.log("Count: " + i); }
Arrays

What will be the result after these operations?

let fruits = ["apple", "banana"]; fruits.push("orange"); console.log(fruits);
Arrays

What is colors[2] for this array?

let colors = ["red", "blue", "green", "yellow"];
Objects

Create an object to represent a book with title "JavaScript Guide":

Objects

How do you access the student's name from this object?

let student = { name: "Sarah", age: 22, courses: ["Math", "Science"] };
DOM

How do you select an element with id "main"?

Events

What event fires when a user clicks on an element?

Debugging

What's wrong with this code?

let name = "Alice" let age = 25 if age > 18 { console.log(name + " is an adult"); }
Code Reading

What will be the final value of x?

let x = 5; let y = 10; if (x < y) { x = x + 2; } console.log("x is now: " + x);
Arrays

Which method removes the last element from an array?

Functions

Convert this function to an arrow function:

function multiply(a, b) { return a * b; }
Integration

Which is the best practice for including JavaScript in HTML?

Quiz Complete! 🎉

0/20