JavaScript Variables and Data Types Worksheet

Question 1

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

JS Keywords
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?

  1. Names can contain letters, digits, underscores(_) and dollar signs($)
  2. Names must begin with a letter
  3. Names can also begin with $ and _
  4. Names are case sensitive
  5. Keywords cannot be used as names
These rules were obtained from here under the JavaScript Identifiers section.
Question 4

What is 'camelCase'?

Start the variable in lowercase and when you get to the next word use an uppercase letter as the first character and then go back to lower case. ex: thisIsAnExampleVariableName
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. Bigint
  5. Undefined
  6. Null
  7. Symbol
  8. Object
This list was obtained here.
Question 6

What is a boolean data type?

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;

In the example, it would treat Jones as another variable and not a string.
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?

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);
string because the variable secondTestScore has "" around its initializing which treats it as 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);
total
99


the word total would be on 1 line in the console and the next would be 99
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
score1 is a number datatype
score2 is a string datatype. It will be treated as text instead of the number.
Question 13

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


const score = 0;
score = prompt("Enter a score");
score is declared as a constant variable meaning it cannot changed and the second part of the code is trying to changed the constant variable. You would have to use let instead of const.

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: