JavaScript Variables and Data Types Worksheet

Question 1

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

W3Schools JavaScript
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?

character limitations, can only use: (a-z)(A-Z)(0-9) the underscore (_) and dollarsign ($)
It can not start with a number
Case sensitive
Can not use words that are used in javascript example; "anchors"
No spaces or special symbols
Question 4

What is 'camelCase'?

Camelcase is used when we cant use spaces, its when you capitalized the first letter of each new word example: thisIsHowToCamelCase
Question 5

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

I just figured a table would work better

Data type description Data type description
Number A numeric value(including decimals) BigInt Ment for large intergers(only whole numbers)
String Holds text characters within quotes Boolean Holds a simple true or false value
Undefined A variable that has yet to be defined Null Represents the absence of an object
Symbol Creates a unique symbol used for identifying Object A collection of pairs of data ex: string: firstname string: lastname object: firstname+lastname
Question 6

What is a boolean data type?

A boolean is a datatype that holds either a true or false vaule
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;

JavaScript will interpret as a variable
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?

it will have the value of 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);
one is a string so they will both be made into strings and put together "988"
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 first log is a string so it will just spit out "total" as its a text value instead of a variable the second log will show 99 as its showing the variable not a string
Question 12

What is the difference between these two variables?


const score1 = 75;
const score2 = "75";
score 1 is a number while score 2 is a string (text)
Question 13

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


const score = 0;
score = prompt("Enter a score");
you cant rewrite a constant

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: