Back to Web Programming 1

JavaScript Variables and Data Types Worksheet

Question 1

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

This shows many JavaScript keywords!!!
Question 2

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

False, having uppercase compared to lowercase and vice versa for words can change what the variable is representing.
Question 3

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

When naming variables, make sure that if you are making a new variable, to not name it the same as an already existing one, or else it will not work. Using camelCase is a great practice that helps everyone understand the intent of the variable.
Question 4

What is 'camelCase'?

Where your variable that contains multiple words has capitalization after the first word. Example - mushroomPizza orangeCatsAreTheBest javaScriptIsCool.
Question 5

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

Null, Undefined, Boolean, Number, BigInt, String, Symbol.
Question 6

What is a boolean data type?

Boolean is used to primarily represent true/false statements.
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;

It tries to read the string as a number value or true/false.
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 most common values that will be stored are 0 or false. It can also 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);
You would see 9888 as the (sum), and string as the (typeof sum).
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);
For ("total") you would see total writen in the console, and for (total) you would see the number 99.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
score1 = number value, while score2 = string.
Question 13

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


const score = 0;
score = prompt("Enter a score");
Because of the const behind score, due to this the prompt will not go through due to score being locked to 0. Replacing the const with let should fix it and allow the value of score to 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: