# JavaScript Variables and Data Types Worksheet

Question 1

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

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?

Variable names must start with a letter, an underscore (_) or a dollar sign ($). Variable names cannot contain spaces. Variables cannot be the same as reserved keywords such as if or const. By convention, JavaScript variable names are written in camelCase.
Question 4

What is 'camelCase'?

The first word is lowercase and each word after is started with an uppercase letter.
Question 5

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

String A text of characters enclosed in quotes Number A number representing a mathematical value Bigint A number representing a large integer Boolean A data type representing true or false Object A collection of key-value pairs of data Undefined A primitive variable with no assigned value Null A primitive value representing object absence Symbol A unique and primitive identifier
Question 6

What is a boolean data type?

A data type representing 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;

If quotes are forgotten around a string when initializing a variable in JavaScript, the interpreter will attempt to interpret the unquoted text as a variable name, property name, or a reserved keyword.
Question 8

What character is used to end a statement in JavaScript?

A semicolon;
Question 9

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

If a variable is declared but not assigned a value, it will hold the special value 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);

The output will be "9888" and "string" because the number is coerced into a string during concatenation.
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);

prints the literal string "total" console.log("total"); // prints the variable value console.log(total); // preferred: print a label and the value console.log("total:", total); console.log(`total = ${total}`);
Question 12

What is the difference between these two variables?

    const score1 = 75;
    const score2 = "75";

score1 is a number data type, while score2 is a string data type.
Question 13

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

    const score = 0;
    score = prompt("Enter a score");

The code will cause a crash due to an attempt to reassign a constant variable.

# 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:

- To do this assignment, you'll need to know how to open the brower's developer tools (press F12) and look at the console log.
- Pay extremely close attention to syntax! One little syntax error can mess up your entire program.
- After you complete each problem, refresh the page in the browser and look in the console your log message and for errors.
- If you have an error in the console, check the line number of the error then look for syntax errors on that line (and the line before and the line after that line).
- If you get stuck on this assignment, please ask for help! Dealing with syntax errors can be extremely frustrating for beginners. It takes a lot of effort and support to get comfortable with the syntax of a language. Don't be afraid to ask for help, your success in this class will depend on your willingness to get help!