Back to Browse

Eloquent Javascript: Chapter 1 (Values, Types, and Operators)

28.4K views
Aug 22, 2021
53:49

The Chee-Tash Podcast: https://rss.com/podcasts/cheetash/. (Apple, Google, Spotify) The Chee-Tash Blog: https://chee-tash.ghost.io/ Eloquent Javascript Book: https://eloquentjavascript.net/ - Data - Values - Binary, unary, and logical Operators - Booleans - Short Circuiting - Type Coercion Slide Information Data -“Inside a computer’s world, there is only data[…]” – P. 11 -All data stored on a computer is by bits. Two valued things 0s and 1s Binary Digits -So anything you want the computer to know or save, ultimately gets interpreted or converted to bits -So if we want to type 13 in a word document and save it… 00001101 0 0 0 0 1 1 0 1 128 64 32 16 8 4 2 1 Values -Separating bits in chunks -Every value has a type -To create a value, just invoke its name -Let x = 5; Types in Javascript Number -Numeric values -A numeric value of 13 will cause the bit representation of that number to be saved into memory on the computer -64 bits to represent a single number value -2^64 possibilities -No all whole numbers less than this fit -Some bits will store the sign, others the decimal -Whole numbers can be precise, fractional..unfortunately not Operators in Javascript -+, -, *, /, % -Modulo is an operator that results in whatever is remaining after division -4 % 2 = 0 So 2 goes into 4, two times, with 0 left over -16 % 5 = 1 5 goes into 16, three times with 1 remaining Special numbers Infinity -Infinity NaN (still a typeOf Number) Will get this when s calculation does not yield a meaningful result Strings -Used to represent text `Hello` ‘Hello’ “Hello” -Modeled as a series of bits, just like numbers Unicode Number is assigned to every character 16 bits per string element -Escape Characters \n \t \” -Concatenation + Combines two strings together “con” + “cat” will yield “concat” Be mindful of spaces when you concatenate… -Template Literals `half of 50 is ${50/2}` Injecting javascript Result is computed, converted to a string, and included at that position Unary Operators -Uses one value -Written as words -Example: typeof operator Console.log(typeof 4.5) Yields number -(-) can be both a unary and binary operator Boolean Values -True/False -==, ===, !=, !==, less than, greater than, less than or equal to, greater than or equal to -Numbers are not the only things that can be compared -Console.log(“Aardvark” less than “Zoroaster”) true So javascript compares letter by letter If first character’s Unicode value is less than or greater than the second, we are finished If characters are the same, then we move to the second If both strings end at the same length, then they are equal, otherwise the longer string is greater. Logical Operators -And && True only if values on both sides of it are true -Or || True if value on just one side is true -Not ! Flips the value given to it !true = false -Precedence || - && - comparison operators Empty Values -Null and undefined Absence of a meaningful value Carry no information Some operations will yield an undefined Not a huge difference between these two Automatic Type Conversion -Type coercion JS will convert that value to the type it needs. When an operator is applied to the wrong value -Console.log(8*null) --- 0 -Console.log(“5”-1) --- 4 -Console.log(“5”+1) --- 51 -Console.log(“five”*2) --- NaN -Console.log(false == 0) --- true -== when types differ on both sides JS will try and convert one of the sides to the other side’s type -When null or undefined, only will produce true of both sides are null or undefined -===, !== Used to check precisely true, no type coercion 0 == false will be true 0 === false will be false Short Circuiting of Logical Operators -|| will return the value to its left when it can be converted to true, else it will return the value to its right -&& works in the opposite way Returns the value to its left it can be converted to something false Else it returns the value on the right -True || X X will never be evaluated in this case -False && X Opposite in this case, X not evaluated because False on the left hand side Same as doing if(false) {X}

Download

0 formats

No download links available.

Eloquent Javascript: Chapter 1 (Values, Types, and Operators) | NatokHD