JavaScript Variables and Data Types Worksheet

Question 1

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

JavaScript Keywords — MDN Reference
Question 2

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

False — JavaScript is case sensitive. Variables like myVar and MyVar are different.
Question 3

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

Variable names must begin with a letter, underscore (_), or dollar sign ($). They cannot start with a number, contain spaces, or use reserved keywords. Variable names are also case sensitive.
Question 4

What is 'camelCase'?

CamelCase is a naming style where the first word is lowercase and each following word begins with a capital letter. Example: myVariableName.
Question 5

What are ALL the different data types in JavaScript?

The JavaScript data types are:
Question 6

What is a boolean data type?

A boolean data type represents one of two values: true or false. It’s often used for conditional testing.
Question 7

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

JavaScript will try to interpret the value as a variable or identifier, not a string. If that variable doesn’t exist, it will throw a ReferenceError.
Question 8

What character is used to end a statement in JavaScript?

A semicolon (;) is used to end a statement.
Question 9

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

It will store 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);
The output will be:
9888
string
        
Because the number is concatenated with the string, resulting in a string.
Question 11

What output will the following program produce?


const total = 99;
console.log("total");
console.log(total);
The output will be:
total
99
        
The first console.log prints the word “total”, the second prints the variable’s value.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
score1 is a Number data type, while score2 is a String data type.
Question 13

Explain why this code will cause the program to crash:


const score = 0;
score = prompt("Enter a score");
It crashes because const variables cannot be reassigned. Use let instead of const if you need to change its value.

Coding Problems