Skip to content

Instantly share code, notes, and snippets.

@Chryus
Last active January 3, 2016 22:29
Show Gist options
  • Save Chryus/8529045 to your computer and use it in GitHub Desktop.
Save Chryus/8529045 to your computer and use it in GitHub Desktop.
>>> 3+2
5
>>> typeof(3);
number
>>> typeof(3) === typeof(4.32);
true
>>> 5/0
Infinity
>>> 5/0;
Infinity
>>> 3/"bob"
NaN
>>> NaN === NaN;
false
>>> typeof(NaN);
number
>>> isNaN(NaN);
true
>>> x = 5
5
>>> var x = 5;
undefined
>>> isNaN(5);
false
>>> Math.pow(2,3);
8
>>> var first_name = "cindy";
undefined
>>> first_name
cindy
>>> typeof(first_name);
string
The var keyword assign the the value "cindy" to "first_name" and also assigns type as string.
>>> var hello;
undefined
>>> hello
undefined
>>> var y;
undefined
>>> y === "cool";
false
>>> y == "cool";
false
the value of y is equal to undefined which doesn't equal "cool".
>>> var first = "Bart";
undefined
>>> var last = "Simpson";
undefined
>>> first
Bart
>>> last
Simpson
>>> first + " " + last
Bart Simpson
Bart is a string and Simpson is a string. Both are operands concatenated by the operator +.
>>> "cool".length;
4
>>> "phat" === "phat";
true
>>> typeof("cats")
string
>>> 3 + "bob"
3bob
>>> String(3);
3
>>> 4.87 - .87
4
>>> x = 6 / "2"
3
>>> typeof(x);
number
javascript coerces "2" into a string to evaluate the expression. it wants to evaluate the expression!
under the hood JS is saying..
>>> Number("2");
2
>>> 3 * "bob"
NaN
>>> var x
undefined
>>> var y
undefined
>>> var hobby = "programming"
undefined
>>> hobby
programming
>>> var sport;
undefined
>>> sport === undefined;
true
>>> typeof("brogrammer");
string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment