JavaScript Variables and Data Types Worksheet

Question 1

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

keywords

Click here to visit the keywords
Question 2

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

Flase
In JavaScript, keywords and variable names are case sensitive.
Question 3

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

  1. Variable names must begin with a letter, underscore (_), or dollar sign ($).

  2. Subsequent characters can include letters, numbers, underscores, and dollar signs.

  3. Variable names are case-sensitive.
Question 4

What is 'camelCase'?

camelCase is a naming convention in programming where the first word of a variable or function name is written in lowercase, and each subsequent word begins with an uppercase letter, without any spaces or punctuation between the words.
Question 5

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

In JavaScript, there are seven basic data types: Number, String, Boolean, Undefined, Null, Symbol and BigInt
Question 6

What is a boolean data type?

A Boolean data type in JavaScript represents one of two possible 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;

If you forget to put quotes around a string when initializing a variable, JavaScript will not interpret it as a string. Instead, it will treat the value as an identifier (variable name) or keyword.
Question 8

What character is used to end a statement in JavaScript?

Semicolon (;) is used to end a statement.
Question 9

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

If you declare a variable in JavaScript but do not initialize it, you don't assign a value to it the variable will be automatically assigned the value of 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 value of sum is "9888", which is 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);
This console.log prints the value of the variable total, which is 99.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
The difference between the two variables is that score1 is a number, and 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");
const score = 0;: You set score as a constant. That's mean you can't change it.
score = prompt("Enter a score");: Here, we're trying to change score, but it's a constant. This causes an error because constants cannot 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: