JavaScript Basics: Variables, Functions & Logic

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 Themes
T
Themes
Community Contributor
Quizzes Created: 3747 | Total Attempts: 1,264,377
| Questions: 30 | Updated: Nov 30, 2026
Please wait...
Question 1 / 31
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. What is the result of "5" + "5" in JavaScript?

Explanation

In JavaScript, both values are strings, so the `+` operator concatenates them rather than adding them numerically. The result is `"55"`.

Submit
Please wait...
About This Quiz
JavaScript Basics: Variables, Functions & Logic - Quiz

Null

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. Given the following function, what does getGrade(83) return?function getGrade(s) { if (s >= 90) { return "A"; } else if (s >= 80) { return "B"; } else if (s >= 75) { return "C"; } else { return "F"; }}

Submit

3. What does 5 === "5" evaluate to in JavaScript?

Submit

4. What does 5 == "5" evaluate to in JavaScript?

Submit

5. What is the difference between === and == in JavaScript?

Submit

6. What are parameters in a JavaScript function?

Submit

7. What value does a function return if no return statement is included?

Submit

8. What is the purpose of the return statement inside a function?

Submit

9. What syntax is used to call a function named greet in JavaScript?

Submit

10. What happens when you define a function but do NOT call it?

Submit

11. What is a function in JavaScript?

Submit

12. How do you fix the string trap when adding two string numbers like "5" and "5"?

Explanation

`"5"` and `"5"` are strings, so `+` may join them into `"55"` rather than add their values. Convert each string to a number with `Number()` first, then add them to get `10`.

Submit

13. What is the result of 10 % 3 in JavaScript?

Explanation

In JavaScript, `%` returns the remainder after division. Since 10 divided by 3 leaves a remainder of 1, `10 % 3` evaluates to `1`.

Submit

14. What does the % operator do in JavaScript?

Explanation

In JavaScript, the `%` operator returns the remainder left over after one number is divided by another. For example, `10 % 3` evaluates to `1`.

Submit

15. What is the result of 5 + 5 in JavaScript?

Explanation

In JavaScript, `5` and `5` are numeric values, so the `+` operator adds them: `5 + 5` evaluates to `10`.

Submit

16. What is the primary purpose of JavaScript in web development?

Explanation

JavaScript adds behavior to web pages, enabling features such as responding to clicks, updating content without reloading, and validating form input. HTML defines page structure, while CSS controls its visual appearance.

Submit

17. What will typeof 42 return?

Explanation

In JavaScript, `typeof` returns `"number"` for numeric values such as `42`. JavaScript does not distinguish integers and floating-point numbers with separate `typeof` results.

Submit

18. What does typeof null return in JavaScript?

Explanation

In JavaScript, `typeof null` returns `"object"` because of a legacy quirk in the language. Despite this result, `null` is a primitive value, not an object.

Submit

19. What is the difference between undefined and null in JavaScript?

Explanation

`undefined` typically indicates that a variable has been declared but has not been given a value. `null` is an explicit value assigned to represent the intentional absence of a value. They are distinct values in JavaScript.

Submit

20. What data type is the value true in JavaScript?

Explanation

In JavaScript, `true` is a Boolean value. The Boolean data type represents one of two values: `true` or `false`.

Submit

21. What data type is the value "Hello" in JavaScript?

Explanation

In JavaScript, text enclosed in quotation marks is a string. Therefore, `"Hello"` has the data type `string`.

Submit

22. Which of the following is a correctly named JavaScript variable using camelCase?

Explanation

CamelCase starts with a lowercase letter and capitalizes the first letter of each following word, with no spaces or underscores. “studentName” follows this pattern.

Submit

23. Which naming convention is the standard for JavaScript variables?

Explanation

JavaScript variables are typically named using camelCase: the first word starts with a lowercase letter, and each following word begins with a capital letter, as in `userName` or `totalPrice`.

Submit

24. Which of the following variable names is INVALID in JavaScript?

Explanation

JavaScript variable names may contain digits, but they cannot begin with one. Since `1score` starts with a digit, it is invalid. The other names begin with a letter, underscore, or dollar sign, all of which are allowed.

Submit

25. Why is the use of var discouraged in modern JavaScript?

Explanation

`var` is function-scoped rather than block-scoped, which can make variables accessible in unexpected places and lead to bugs. Modern JavaScript generally favors `let` and `const`, whose block-scoping makes variable behavior more predictable.

Submit

26. Which keyword should you use when a variable's value needs to change later?

Explanation

Use `let` when a variable’s value may be reassigned later. It is block-scoped and is generally preferred over `var` for variables that need to change.

Submit

27. Which keyword is used to declare a variable that CANNOT be reassigned?

Explanation

`const` declares a variable binding that cannot be reassigned after it is initialized. For objects and arrays, their contents may still be modified.

Submit

28. What does console.log() do in JavaScript?

Explanation

`console.log()` outputs the given value or message to the browser’s DevTools console, where developers can inspect it while debugging. It does not display the message on the web page or send it to a server.

Submit

29. Where should the <script src> tag be placed in an HTML document?

Explanation

Placing the `

Submit

30. Which of the following is the recommended way to include JavaScript in an HTML file?

Explanation

Using an external JavaScript file keeps behavior separate from HTML, making code easier to maintain and reuse across pages. Browsers can also cache the file, which may improve loading performance. Link it with a `` tag.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (30)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the result of "5" + "5" in JavaScript?
Given the following function, what does getGrade(83) return?function...
What does 5 === "5" evaluate to in JavaScript?
What does 5 == "5" evaluate to in JavaScript?
What is the difference between === and == in JavaScript?
What are parameters in a JavaScript function?
What value does a function return if no return statement is included?
What is the purpose of the return statement inside a function?
What syntax is used to call a function named greet in JavaScript?
What happens when you define a function but do NOT call it?
What is a function in JavaScript?
How do you fix the string trap when adding two string numbers like "5"...
What is the result of 10 % 3 in JavaScript?
What does the % operator do in JavaScript?
What is the result of 5 + 5 in JavaScript?
What is the primary purpose of JavaScript in web development?
What will typeof 42 return?
What does typeof null return in JavaScript?
What is the difference between undefined and null in JavaScript?
What data type is the value true in JavaScript?
What data type is the value "Hello" in JavaScript?
Which of the following is a correctly named JavaScript variable using...
Which naming convention is the standard for JavaScript variables?
Which of the following variable names is INVALID in JavaScript?
Why is the use of var discouraged in modern JavaScript?
Which keyword should you use when a variable's value needs to change...
Which keyword is used to declare a variable that CANNOT be reassigned?
What does console.log() do in JavaScript?
Where should the <script src> tag be placed in an HTML document?
Which of the following is the recommended way to include JavaScript in...
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!