JavaScript Variables and Data Types Worksheet

Question 1

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

Here is my List
Question 2

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

False, they are case sensitive. Referring to myvar won't work unless it is myVar.
Question 3

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

Variables are case sensitive and there shouldn't be any spaces. They should use camelCase so that they can be properly referenced.
Question 4

What is 'camelCase'?

camelCase is how you should name variables in JavaScript. The first letter of each word is lowercase and the first letter of each word after that is uppercased. There are no spaces between words.
Question 5

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

The data types I know of are string, number, and boolean. There is also symbol, undefined, and null.
Question 6

What is a boolean data type?

Boolean data types can only be 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;

JavaScript will consider it a variable and will look for the variable named Jones. This can lead to errors if there is not a variable named Jones.
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?

The variable will say that it is missing an initializer. The type will be undefined.
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);
The console will say "9888" and the type will be string. This is because the secondTestScore is initialized in quotes, so it's 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);
The console will say "total", then 99 because it was told to log the string "total", and then log the variable that is initialized as total.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
The first variable is a number and the second is a string because it is in quotes.
Question 13

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


const score = 0;
score = prompt("Enter a score");
The variable score is a constant so it can't be changed from 0. On the 2nd line, it is being told to change the value, which contradicts the const rule.

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: