Skip to main content


Showing posts with the label primitives

Solutions: Object Oriented JavaScript: Chapter 2: Primitives

JavaScript experts can skip this.   While reading the book, Object Oriented JavaScript by Stoyan Stefanov , I thought it would be a good idea to just solve the exercises presented in the book and store the solutions away. Takes me back to my school days when I was serious about learning stuff :) This will be a multi-part blog, with each blog entry solving exercises presented in one chapter of the book. The entire set of solutions will be eventually made available in my JavaScript site. So here goes ...   Chapter 2: Primitive Data Types, Arrays, Loops and Conditions   1. What is the result of executing each of these lines in the console? Why? >> var a; typeof a; undefined  // a has not been defined with any value >> var s = '1s'; s++; NaN  // converting 1s to a number is ambiguous with addition   >> !!"false" true  // "false" is a valid string   >> !!undefined false  //undefined is a falsy   >> typeof -Infinity "

JavaScript - Undefined Infinity or Not a Number?

Had a heated discussion with a friend about a particular expression and so this blog with ready references for some basic JavaScript expressions. Expression Value Infinity Anything beyond +/-1.7976931348623157e+308 typeof Infinity "number" typeof NaN "number" typeof undefined "undefined" typeof null "object" Infinity + Infinity Infinity Infinity - Infinity NaN -Infinity + Infinity NaN Infinity / Infinity NaN Infinity * Infinity Infinity Infinity * 1 Infinity Infinity / 1 Infinity Infinity / 0 Infinity Infinity * 0 NaN Infinity - 1e308 Infinity Infinity - 1e309 NaN -Infinity + 1e308 -Infinity -Infinity + 1e309 NaN Infinity / 1e308 Infinity 1 * "a" NaN 1 + NaN NaN 1 * NaN NaN undefined + 1 NaN undefined * 1 NaN undefined + Infinity NaN undefined * Infinity NaN undefined + NaN NaN undefined * NaN NaN undefined + null NaN undefined * null NaN 1 + null 1 1 * null 0 null + null 0 null * null 0 Infinity + null Infinity Infinity * null NaN NaN