JavaScript Variables and Data Types Worksheet

Question 1

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

JavaScript Reserved Words
Question 2

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

This is false: keywords are in fact case sensitive.
Question 3

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

Some of the rules for naming a variable are: starting them with a letter, underscore _, or dollar sign $, After the first letter, you can use numbers, as well as letters, underscores, or dollar signs, Do not use any of JavaScript reserved keywords in naming a variable,and remember that variables are case sensitive. Other rules include using camelCase, being descriptive, and using meaningful prefixes.
Question 4

What is 'camelCase'?

The use of 'camelCase' is used in code because you cannot put spaces bewteen words. camelCase requires you to start all of your variable names with a lowercase letter, and use a capital letter (instead of a space) when there's a new word.
Question 5

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

There are 8 data types in JavaScript: String, Number, Bigint, Boolean, Undefined, Null, Symbol, and Object. According to research the Object data type has two types Built-in objects and user defined objects with 'built-in objects' can have: objects, arrays, dates, maps, set, intarrays, floatarrays, promises, and others.
Question 6

What is a boolean data type?

A JavaScript Boolean represents one of two values: true or false. According to my research a boolean data type is used in programming to represent one of two values; like true/false or yes/no.
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;

Where there are no quotes surrounding the word, JavaScript will assume that the variable is named jones. If you have not declared a variable named Jones, the program will crash.
Question 8

What character is used to end a statement in JavaScript?

A semicolon (;) is used to end a statement in JavaScript
Question 9

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

Uninitialized variables cause a compliation error. Variables that are not initialized are set to default values: Null for objects and 0 for integers.
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);
9888
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);
total
99
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
const score1 is a number
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 we set const to 0 it, cannot change. With the second line of code that says score = prompt("Enter a score") will give an error because it cannot change. Essentially the second line is trying to change the value of score from 0 to "a score" which cannot happen.

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: