JavaScript Variables and Data Types Worksheet

Question 1

Find a reference that lists all the keywords in the JavaScript programming language.

JavaScript Keyword Reference – MDN Web Docs
Question 2

True or false: keywords and variable names are NOT case sensitive.

False. JavaScript is case sensitive, which means keywords and variable names must be written with the correct capitalization.
Question 3

There are some rules for how you can name variables in JavaScript. What are they?

Variable names in JavaScript must follow these rules:
Question 4

What is 'camelCase'?

camelCase is a common naming convention in JavaScript where: Example: myVariableName
Question 5

What are ALL the different data types in JavaScript?

JavaScript has the following data types:
Question 6

What is a boolean data type?

A Boolean is a data type that can only have one of two values: true or false. It’s often used for conditional statements and logical tests.
Question 7

What happens if you forget to put quotes around a string when you initialize a variable to a string value?

If you forget quotes around a string (e.g., var lastName = Jones;), JavaScript will try to interpret Jones as a variable name, not a string, which will cause a ReferenceError if that variable doesn’t exist.
Question 8

What character is used to end a statement in JavaScript?

Statements in JavaScript are typically ended with a semicolon (;). Although semicolons are optional in most cases, using them avoids potential automatic semicolon insertion errors.
Question 9

If you declare a variable, but do not initialize it, what value will the variable store?

If a variable is declared but not initialized, it will have the value undefined.
Question 10

What output will the following program produce?


const firstTestScore = 98;
const secondTestScore = "88";
const sum = firstTestScore + secondTestScore;
console.log(sum);
console.log(typeof sum);
Output:
9888
string
Explanation: The number 98 is converted to a string and concatenated with "88", resulting in the string "9888".
Question 11

What output will the following program produce?


const total = 99;
console.log("total");
console.log(total);
Output:
total
99
Explanation: The first console.log("total") prints the string "total", not the variable. The second prints the value stored in the variable total.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
score1 is a number, while score2 is a string containing numeric characters. They look the same, but they are different data types.
Question 13

Explain why this code will cause the program to crash:


const score = 0;
score = prompt("Enter a score");
The variable score is declared with const, which means its value cannot be reassigned. Trying to reassign it causes a TypeError. To fix this, use let instead of const.

Coding Problems