JavaScript Variables and Data Types Worksheet

Question 1

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

You can explore a detailed list of JavaScript keywords on the MDN Web Docs.
Question 2

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

False. Keywords and variable names in JavaScript are case sensitive.
Question 3

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

Variable names must start with a letter, _, or $. They can only include letters, numbers, _, or $. Names are case-sensitive. Reserved keywords cannot be used.
Question 4

What is 'camelCase'?

CamelCase is a naming style where the first letter of each word is capitalized, except for the first word, like "myVariableName."
Question 5

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

1. String 2. Number 3. Boolean 4. Undefined 5. Object
Question 6

What is a boolean data type?

A boolean data type represents one of two possible values: true or false. It's commonly used in conditions and logical operations to make decisions in a program.
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 quotes, JavaScript treats it as a variable name. If it's not defined, you'll get a "ReferenceError". Use quotes like this: var lastName = "Jones";.
Question 8

What character is used to end a statement in JavaScript?

The semicolon (;) is used to end a statement in JavaScript. For example: console.log(name);
Question 9

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

If you declare a variable but do not initialize it, it will store the value "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 number is converted to a string, so the sume is "988", and its type is "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);
The output of it is the first line prints the string "total", and the second line 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";
score1 is a number, while 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");
The code looks like it crash because the code crashes because score is a constant and can't be reassigned. Trying to change its value with score = prompt("Enter a score"); results in an error.

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: