JavaScript Variables and Data Types Worksheet

Question 1

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

https://www.w3schools.com/js/js_reserved.asp
Question 2

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

True, keywords and variables are case sensitive.
Question 3

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

Use camelCase to name variables in JavaScript. Use words, letters, and underscores only.
Question 4

What is 'camelCase'?

theAct of naming thingsIn thisStyle, Not In PascalCase or snake_case
Question 5

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

String for a string of characters. Number for integers or decimals. Bigint for numbers up to a 64-bit floating point format. Boolean for true and false (1 and 0). Undefined for variables that don't have a definition such as string or number. Null Symbol Object
Question 6

What is a boolean data type?

True or false (0 and 1).
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 won't print.
Question 8

What character is used to end a statement in JavaScript?

Semi-colon;
Question 9

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

null;
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);
"number"
Question 11

It will add together both test scores.


const total = 99;
console.log("total");
console.log(total);
It will print: total 99
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
One is a string that can't be interacted mathematically and one is a number / integer that can be interacted mathematically.
Question 13

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


const score = 0;
score = prompt("Enter a score");
You are trying to assign a function/method to a variable.

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: