JavaScript Variables and Data Types Worksheet

Question 1

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

Keywords Cheat Sheet
Java Data Types
Question 2

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

False, keywords and variable are case senseitive
Question 3

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

They must start with a lowercase letter, contain no spaces, and can't be the same as keyword
Question 4

What is 'camelCase'?

camelCase is a way of separating word in a phrase without spaces
Question 5

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

byte, short, int, long, float, double, boolean, and chr
Question 6

What is a boolean data type?

A value being either true or false but nothing else
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 would assume Jones was a value/variable and would crash
Question 8

What character 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?

It'll be assigned a default value
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);
it would put both 98 and 88 together to make 9888
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);
It would show as 2 line one showing total sense console.log("total") is in a string it would just show as total
Then it would show 99 because of total has a value of 99 show it would show as 99.
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
One is a data type and the other is a String
Question 13

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


const score = 0;
score = prompt("Enter a score");
Sense score = 0 is a const it can not be changed which is why the second line of code would make this program crash

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: