JavaScript introduction 1 ( Variables And Values )

1,090 views

Published on

First JavaScript presentation for 24/i

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,090
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
24
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

JavaScript introduction 1 ( Variables And Values )

  1. 1. JAVASCRIPT VARIABLES AND VALUES Victor Perez
  2. 2. / INTRODUCTION
  3. 3. ⁄⁄⁄ ● Brendan Eich ● Mocha ● September, 1995 LiveScript ● December, 1995 JavaScript ● June, 1997 ECMAScript 1 ● June, 1998 ECMAScript 2 ● December, 1999 ECMAScript 3 ● December, 2009 ECMAScript 5 ● June, 2011 ECMAScript 5.1 ● JScript HISTORY INTRODUCTION
  4. 4. ⁄⁄⁄ JAVASCRIPT INTRODUCTION document.getElementById() navigator.battery.charging new Array() console.log() process.on() encodeURI() JSON.parse() new XMLHttpRequest() DOM API Device API JavaScript Plugin API / Host Object Node.js API JavaScript JavaScript DOM API
  5. 5. ⁄⁄⁄ GLOBAL OBJECTS INTRODUCTION Value properties Infinity, NaN and undefined Function properties eval(), isFinite(), isNaN(), parseFloat(), parseInt(), decodeURI(), decodeURIComponent(), encodeURI() and encodeURIComponent() Deprecated: escape() and unescape() Objects Object(), Function(), Boolean(), Error(), EvalError(), RangeError(), ReferenceError(), SyntaxError(), TypeError(), URIError(), Number(), Math(), Date(), String(), RegExp(), Array(), JSON() ECMAScript 6: Float32Array(), Float64Array(), Int8Array(), Int16Array(), Int32Array(), Uint8Array(), Uint16Array(), Uint32Array(), Uint8ClampedArray(), Symbol(), Map(), Set(), WeakMap(), WeakSet(), ArrayBuffer(), DataView(), Generator(), Promise(), Reflect(), and Proxy() Function scope arguments
  6. 6. / VARIABLES
  7. 7. ⁄⁄⁄ ● Must begin with: ○ a letter from the Unicode character set ○ $ dollar sign ○ _ underscore ● Subsequent characters can be: ○ letters and digits from the entire Unicode character set ○ dollar signs ○ underscores ● Reserved words are not allowed *next slide IDENTIFIERS INTRODUCTION
  8. 8. ⁄⁄⁄ RESERVED WORDS INTRODUCTION Keywords & literals break, delete, function, return, typeof, case, do, if, switch, var, catch, else, in, this, void, continue, instanceof, throw, while, debugger, finally, new, with, default, for, null and try literals: true and false Future reserved words class, enum, extends, super, const, export and import Strict mode implements, let, private, public, yield, interface, package, protected and static also: arguments and eval ECMAScript 3 abstract, double, goto, native, static, boolean, enum, implements, package, super, byte, export, import, private, synchronized, char, extends, int, protected, throws, class, final, interface, public, transient, const, float, long, short, volatile
  9. 9. ⁄⁄⁄ ● Keyword var ● Declare multiple variables with the same var keyword ● Declared variables will contain the value undefined ● Initialize a variable ● Dynamic typing ● Repeated and omitted declarations DECLARATION VARIABLES
  10. 10. ⁄⁄⁄ ● global and function scope SCOPE VARIABLES
  11. 11. ⁄⁄⁄ ● No block scoping ● Will be added in ECMAScript 6 via keyword let HOISTING VARIABLES
  12. 12. / VALUES
  13. 13. ⁄⁄ V ⁄ DATA TYPES VALUES Primitive Number 25 25.5 String "string" 'also a string' Boolean true false Special Undefined undefined void 0 Null null Composite Object {a: 1, b: "string", c: true} new String () Array [1, "string", true] new Array ()
  14. 14. ⁄⁄⁄ ● Integer values and floating-point values ● double-precision 64-bit binary format IEEE 754 value ● Number.MAX_VALUE ± 1.7976931348623157e+308 ● Number.MIN_VALUE ± 5e-324 ● Integer between 2^53 and -2^53 (2^53 = 9007199254740992) ● Number.POSITIVE_INFINITY Infinity round(r) > Number.MAX_VALUE ● Number.NEGATIVE_INFINITY -Infinity round(r) < Number.MIN_VALUE ● Number.NaN NaN Not a Number NUMBERS VALUES
  15. 15. ⁄⁄⁄ WORKING WITH NUMBERS VALUES ● Math https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
  16. 16. ⁄⁄⁄ ● Sequences of unsigned 16-bit values ● Immutable ● UTF-16 ● String.length ○ Surrogate pair TEXT VALUES
  17. 17. ⁄⁄⁄ WORKING WITH STRINGS VALUES
  18. 18. ⁄⁄⁄ ● true ● false ● 3 == 1 false ● 3 == 3 true BOOLEANS VALUES
  19. 19. ⁄⁄⁄ ● keyword null ● undefined ○ not initialized ○ default return value of a function ○ function parameters for which no argument is supplied ● null & undefined don’t have any properties UNDEFINED & NULL VALUES
  20. 20. ⁄⁄⁄ ● Create ● mutable ● Comparison ○ Not by value ○ By reference OBJECTS (BASIC) VALUES
  21. 21. ⁄⁄⁄ ● string inherits String object ● number inherits Number object ● boolean inherits Boolean object ● Immutable WRAPPER OBJECTS VALUES
  22. 22. ⁄⁄⁄ ● Specialized object ● Zero-based ● 32-bit indexes ○ From 0 up to 4294967294 ( 2^32 - 2) ● Max elements 4294967295 ( 2^32 - 1) ○ RangeError ● mutable ARRAYS VALUES
  23. 23. ⁄⁄⁄ WORKING WITH ARRAYS VALUES
  24. 24. ⁄⁄⁄ TYPEOF VALUES Value Result Notes Undefined "undefined" Null "object" bug http://www.2ality.com/2013/10/typeof-null.html Boolean "boolean" Number "number" String "string" Function object "function" Implements [[Call]] in ECMAScript terms Any other object "object" Other Array "object" Array.isArray() /a/ "object" / "function" in some browser "object" is conform to ECMAScript 5.1 IE < 9: typeof alert "object" Most old IE host objects where objects and not functions
  25. 25. / TYPE CONVERSIONS
  26. 26. ⁄⁄⁄ AUTOMATICALLY TYPE CONVERSIONS ● To number ○ +anyType or -anyType ○ anyType -, *, / or % anyType ○ boolean, number or null + boolean, number or null ● To string ○ anyType + anyType ( as long both aren't a number, boolean or null) ● To boolean ○ !anyType ● Comparison operators ( except the strict equality ) ○ valueOf() and toString()
  27. 27. ⁄⁄⁄ EXPLICIT TYPE CONVERSIONS ● Number() ○ parseInt(string, radix) ○ parseFloat(string) ● String() ● Boolean() ● Object()
  28. 28. ⁄⁄⁄ NUMBERS TYPE CONVERSIONS Value String Boolean Object 0 "0" false new Number() or new Number(0) -0 "0" false new Number(-0) NaN "NaN" false new Number(NaN) Infinity "Infinity" true new Number(Infinity) -Infinity "-Infinity" true new Number(-Infinity) 1 ( any number > 0 ) "1" true new Number(1) -1 ( any number < 0) "-1" true new Number(-1)
  29. 29. ⁄⁄⁄ STRINGS TYPE CONVERSIONS Value Number Boolean Object "24" 24 true new String("24") "foo" NaN true new String("foo"); "" ( empty string ) 0 false new String() or new String("")
  30. 30. ⁄⁄⁄ BOOLEANS TYPE CONVERSIONS Value Number String Object true 1 true new Boolean(true) false 0 false new Boolean() or new Boolean(false);
  31. 31. ⁄⁄⁄ UNDEFINED & NULL TYPE CONVERSIONS ● Can’t be convert to a Object Value Number String Boolean undefined NaN "undefined" false null 0 "null” false
  32. 32. ⁄⁄⁄ OBJECTS TYPE CONVERSIONS ● From object to string ○ toString() ○ valueOf() ● From object to number ○ valueOf() ○ toString() ● From object to boolean always true Value Number String Boolean new Object() NaN "[object Object]" true
  33. 33. ⁄⁄⁄ STANDARD BUILT-IN OBJECTS TYPE CONVERSIONS Value String Number new Date() "Tue Apr 22 2014 12:13:49 GMT+0200" * http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.5.2 1398165557386 Date.getTime() new RegExp('^foo', 'i') "/^foo/i" NaN new Array() (empty array) "" Array.join() 0 new Array([24]) (array with a single element) "24” Array.join() 24 or NaN if the value can’t be cast to a number new Array([24, "i"]) "24,i” Array.join() NaN function (x, y) { return x + y; } "function (x, y) { return x + y; }" * http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.2 NaN new Error("foo") new TypeError("foo") "Error: foo" "TypeError: foo" NaN
  34. 34. / QUESTIONS?
  35. 35. THANKS @VICTORAPEREZ vpjs@victor-perez.nl

×