JavaScript introduction 1 ( Variables And Values )
Upcoming SlideShare
Loading in...5
×
 

JavaScript introduction 1 ( Variables And Values )

on

  • 401 views

First JavaScript presentation for 24/i

First JavaScript presentation for 24/i

Statistics

Views

Total Views
401
Views on SlideShare
395
Embed Views
6

Actions

Likes
1
Downloads
8
Comments
0

3 Embeds 6

https://www.linkedin.com 3
http://192.168.6.179 2
https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

JavaScript introduction 1 ( Variables And Values ) JavaScript introduction 1 ( Variables And Values ) Presentation Transcript

  • JAVASCRIPT VARIABLES AND VALUES Victor Perez
  • / INTRODUCTION
  • ⁄⁄⁄ ● 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
  • ⁄⁄⁄ 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
  • ⁄⁄⁄ 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
  • / VARIABLES
  • ⁄⁄⁄ ● 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
  • ⁄⁄⁄ 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
  • ⁄⁄⁄ ● 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
  • ⁄⁄⁄ ● global and function scope SCOPE VARIABLES
  • ⁄⁄⁄ ● No block scoping ● Will be added in ECMAScript 6 via keyword let HOISTING VARIABLES
  • / VALUES
  • ⁄⁄ 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 ()
  • ⁄⁄⁄ ● 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
  • ⁄⁄⁄ WORKING WITH NUMBERS VALUES ● Math https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
  • ⁄⁄⁄ ● Sequences of unsigned 16-bit values ● Immutable ● UTF-16 ● String.length ○ Surrogate pair TEXT VALUES
  • ⁄⁄⁄ WORKING WITH STRINGS VALUES
  • ⁄⁄⁄ ● true ● false ● 3 == 1 false ● 3 == 3 true BOOLEANS VALUES
  • ⁄⁄⁄ ● 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
  • ⁄⁄⁄ ● Create ● mutable ● Comparison ○ Not by value ○ By reference OBJECTS (BASIC) VALUES
  • ⁄⁄⁄ ● string inherits String object ● number inherits Number object ● boolean inherits Boolean object ● Immutable WRAPPER OBJECTS VALUES
  • ⁄⁄⁄ ● 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
  • ⁄⁄⁄ WORKING WITH ARRAYS VALUES
  • ⁄⁄⁄ 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
  • / TYPE CONVERSIONS
  • ⁄⁄⁄ 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()
  • ⁄⁄⁄ EXPLICIT TYPE CONVERSIONS ● Number() ○ parseInt(string, radix) ○ parseFloat(string) ● String() ● Boolean() ● Object()
  • ⁄⁄⁄ 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)
  • ⁄⁄⁄ 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("")
  • ⁄⁄⁄ BOOLEANS TYPE CONVERSIONS Value Number String Object true 1 true new Boolean(true) false 0 false new Boolean() or new Boolean(false);
  • ⁄⁄⁄ UNDEFINED & NULL TYPE CONVERSIONS ● Can’t be convert to a Object Value Number String Boolean undefined NaN "undefined" false null 0 "null” false
  • ⁄⁄⁄ 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
  • ⁄⁄⁄ 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
  • / QUESTIONS?
  • THANKS @VICTORAPEREZ vpjs@victor-perez.nl