JavaScript Variables and Data Types Worksheet

Question 1

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

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
Question 2

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

False
Question 3

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

Variable names must start with a letter, underscore(_), or dollar sign($). Subsequent characters can be letters, numbers, underscores, or dollar signs. Variable names should not contain spaces.
Question 4

What is 'camelCase'?

CamelCase is a naming convention where multiple words are combined into a single string, starting with a lowercase letter and capitalizing subsequent words (example: firstName, userAge)
Question 5

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

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

What is a boolean data type?

Boolean data type represents a logical entity and is inhabited by two values; 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 think you're tring to use a vaiable name instead of a string. If the variable doesn't exist, JavaScript will show an error saying that it doesn't know what the variable is.
Question 8

What character is used to end a statement in JavaScript?

Semicolon (;)
Question 9

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

The variable will store a special value called 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 first console.log will ouptut a 9888, which is a string and the second console.log will output string, since the result of the addition is a string.
The firstTestScore is a number while the secondTestScore is a string with the Quotation marks. 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 first console.log() outputs the string "total" as just text. The second console.log() outputs the value of the variable total, which is a number 99.
Question 12

What is the difference between these two variables?


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

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


const score = 0;
score = prompt("Enter a score");
Because it attempts to reassign a value that has been declared as const, which is not allowed. Once you assign a value to a const variable, you cannot reassign a new value to it.

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: