JavaScript Variables and Data Types Worksheet

Question 1

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

Here you go.
Question 2

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

False. Casing is important in JavaScript
Question 3

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

Case sensitivity, no spaces, no dashes. The general rule is to use camel case.
Question 4

What is 'camelCase'?

Closing words together and capitalizing the first letter of the subsequent words. e.g. fileNameExample
Question 5

What are ALL the different data types in JavaScript (note that there are some that we did not discuss in class)?

Examples include strings, numbers, booleans...
Question 6

What is a boolean data type?

A status or answer to a question, e.g. true or false.
Question 7

What happens if you forget to put quotes around a string when you initialize a variable to a string value? How does JavaScript try to interpret this?
For example: var lastName = Jones;

The program interprets it as a name to another variable.
Question 8

What character is used to end a statement in JavaScript?

A semicolon. | ; |
Question 9

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

A "const" variable will crash the program. A "let" variable will be stored as null, or no value, expecting to be defined down the line.
Question 10

What output will the following program produce? In other words, explain what you would see in the console log if you ran a program like this:


const firstTestScore = 98;
const secondTestScore = "88";
const sum = firstTestScore + secondTestScore;
console.log(sum);
console.log(typeof sum);
"console.log(sum);" returns "9888"
"console.log(typeof sum);" returns "string"
This is because using a "+" between a number and a string will initiate a string concatenation, and interpret the number as a string.
Question 11

What output will the following program produce? In other words, explain what you would see in the console log if you ran a program like this:


const total = 99;
console.log("total");
console.log(total);
"console.log("total");" returns the word "total".
This is because in "console.log("total");", "total" is in quotes, marking it as a string.
"console.log(total);" returns the number 99.
This is because in "console.log(total);", "total" is not in quotes, calling the variable defined previously.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
"const score1 = 75;" initializes the variable as a number.
"const score2 = "75";" initializes the variable as a string.
Question 13

Explain why the this code will cause the program to crash:


const score = 0;
score = prompt("Enter a score");
The second line tries to redefine the "score" variable, but it is a const variable, meaning it cannot be changed.

Coding Problems

Coding Problems - See the 'script' element below this h1 element. You will have to write some JavaScript code in it.

Here are some tips to help you with the coding problems: