JavaScript Variables and Data Types Worksheet

Question 1

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

Reference List
Question 2

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

Keywords and variables ARE sensitive. False
Question 3

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

You must use camelCase when inputting variables and you also cannot put spaces into the variables.
Question 4

What is 'camelCase'?

camelCase requires that you start all your variables with lowercase letters and that you use a capital letter when declaring a space
Question 5

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

String, Number, BigInt, Boolean, Undefined, Null, Symobl, Object, Array, Function
Question 6

What is a boolean data type?

Boolean means that a value can be either true or false nothing else.
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;

When you forget to put quotes around a string your program assumes that it is a value already and will search for it and when it doesn't find the variable it will crash.
Question 8

What character is used to end a statement in JavaScript?

the character that is used to end a statement in javascript is a ;
Question 9

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

For class or instance fields, variables do get a default value if you dont initialize them. Primitive types get initiated to zero for numeric types, false for booleans. For reference types, like String, the reference gets initialized to the null pointer.
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 the sum of the test scores
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);
You would see the constant variable of 99.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
One has been initialized into a string. and one is a number value.
Question 13

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


const score = 0;
score = prompt("Enter a score");
You will get an error because score was already delcared a 0 with the const. putting in another score would result in the program to crash

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: