JavaScript Variables and Data Types Worksheet

Question 1

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

My reference listing: JavaScript Keywords (MDN)
Question 2

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

False, the keywords are case sensitive.
Question 3

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

Variable names must have to start with a letter, _, or $. Also can not start with a number or reserved words and be case sensitive.
Question 4

What is 'camelCase'?

camelCase is a naming convention in wjich the first worf is in lowercase, and each word begins with an uppercase, with no spaces or underscores.
Question 5

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

Some Data types like: String, number, symbol, boolean and others includes arrays, and functions.
Question 6

What is a boolean data type?

A Boolean holds only 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;

It will cause a error because without the quotes, JavaScript treats the text as a variable name and not a string.
Question 8

What character is used to end a statement in JavaScript?

statement end with a semicolon.
Question 9

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

It will has the value underfine.
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 output will be: 9888
String
Because the number is converted to a string and concatenated.
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 will be:
total
99
The first logs a string, the second logs the variable value.
Question 12

What is the difference between these two variables?


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

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


const score = 0;
score = prompt("Enter a score");
It will crash because the const variables can't be reassigned.

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: