Last active
January 3, 2016 22:29
-
-
Save sranso/8528881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Perform these exercises in the JavaScript console of your favorite web browser. | |
What does the following expression return? | |
> 3 + 2; | |
5 | |
============================================================= | |
What does the following expression return? | |
> typeof(3); | |
number | |
============================================================= | |
What does the following expression return? | |
> typeof(3) === typeof(4.32); | |
true | |
============================================================= | |
What does the following expression return? | |
> 5 / 0; | |
Infinity | |
============================================================= | |
What does the following expression return? | |
> 3 / "bob"; | |
NaN | |
============================================================= | |
What does the following expression return? | |
> NaN === NaN; | |
false; | |
============================================================= | |
What does the following expression return? | |
> typeof(NaN); | |
number | |
============================================================= | |
What does the following expression return? | |
> isNaN(NaN); | |
true | |
============================================================= | |
What does the following expression return? | |
> Math.pow(2, 3); | |
8 | |
============================================================= | |
Describe how the following expression assigns a variable to a value. | |
> var first_name = "cindy"; | |
first_name is instantiated as a var when "var first_name" is typed; it is initialized when it is set equal to "cindy" | |
============================================================= | |
What is the value of the hello variable in the following expression? | |
> var hello; | |
undefined | |
============================================================= | |
What does the following expression return? | |
> var y; | |
> y === "cool"; | |
false (because y was declared but not assigned to anything, so it is undefined, therefore not eq to anything) | |
============================================================= | |
What does the following expression return? | |
> "some" + " person"; | |
some person | |
============================================================= | |
What does the following expression return? | |
> var first = "Bart"; | |
> var last = "Simpson"; | |
> first + " " + last | |
Bart Simpson | |
============================================================= | |
What does the following expression return? | |
> "cool".length; | |
4 | |
============================================================= | |
What does the following expression return? Explain the answer. | |
> "phat" === "phat"; | |
true--they are the same in both value and type | |
============================================================= | |
What does the following expression return? | |
> typeof("cats"); | |
string | |
============================================================= | |
What does the following expression return? | |
> 3 + "bob" | |
3bob | |
============================================================= | |
Round the number 4.87 to the nearest integer. | |
Math.round(4.87); | |
============================================================= | |
Divide the number 6 by the string "2" and explain the result. | |
3--because js can't divide a number by a string, it converts the string to a num and performs the result | |
============================================================= | |
What does the following expression return? Explain the result. | |
> 3 * "bob"; | |
NaN--because js can't multiple a number by a string, it tries to convert the string into a number and learns that "bob" is not a number. | |
============================================================= | |
Declare the variables x and y. | |
var x, y; | |
============================================================= | |
Set the variable hobby to the string "programming". | |
var hobby = "programming"; | |
============================================================= | |
What does the following expression return? | |
> var sport; | |
> sport === undefined | |
true | |
============================================================= | |
Demonstrate that "brogrammer" has the type "string". | |
typeof("brogrammer"); | |
string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment