JavaScript Variables and Data Types Worksheet
Question 1Find a reference that lists all the keywords in the JavaScript programming language.
Question 2True or false: keywords and variable names are NOT case sensitive.
There are some rules for how you can name variables in JavaScript. What are they?
- They must begin with a letter, underscore (
_), or dollar sign ($). - They cannot start with a number.
- They can contain letters, digits, underscores, and dollar signs.
- They are case sensitive (for example,
myVarandmyvarare different). - They cannot use JavaScript reserved keywords (like
let,class, orreturn).
What is 'camelCase'?
- The first word starts with a lowercase letter.
- Each following word starts with an uppercase letter.
myVariableName
What are ALL the different data types in JavaScript?
- Primitive types: String, Number, Boolean, Undefined, Null, Symbol, BigInt
- Non-primitive type: Object (includes arrays, functions, and other complex structures)
What is a boolean data type?
true or false.
It’s often used for conditional statements and logical tests.
What happens if you forget to put quotes around a string when you initialize a variable to a string value?
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.
What character is used to end a statement in JavaScript?
If you declare a variable, but do not initialize it, what value will the variable store?
undefined.
What output will the following program produce?
const firstTestScore = 98;
const secondTestScore = "88";
const sum = firstTestScore + secondTestScore;
console.log(sum);
console.log(typeof sum);
9888 stringExplanation: The number
98 is converted to a string and concatenated with "88", resulting in the string "9888".
What output will the following program produce?
const total = 99;
console.log("total");
console.log(total);
total 99Explanation: The first
console.log("total") prints the string "total", not the variable.
The second prints the value stored in the variable total.
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.
Explain why this code will cause the program to crash:
const score = 0;
score = prompt("Enter a score");
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.