Download presentation
Presentation is loading. Please wait.
Published byShakira Bradby Modified over 9 years ago
1
By: Daniel Henneberger
3
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
4
Prototype-based scripting language Interpreted? Chrome V8 attempts to compile Java’s Rhino attempts to compile to byte code Mozilla attempts JIT Garbage Collection – Up to implementer Loosely-typed, First-class functions, dynamic Java-like syntax Two Subsets Default Language (will be abandon later) Strict Language Free The word JavaScript must be licensed by Oracle Mozilla has ‘Inventor rights’ Brief
5
Developed for client-side processing on web browsers Now capable of other tasks Web Servers (node.js) Desktop Widgets Inside Applications Applications
6
Originally Called LiveScript 1995- Created for Netscape Navigator by Brendan Eich 1995- Renamed JavaScript Most likely a marking ploy 1996- Microsoft created Jscript 1998- Formalized to ECMAScript 1998- ISO/IEC 16262 1998- ECMAScript v2 1999- ECMAScript v3 History of JavaScript
7
1999-2009 – ECMAScript v4 (Abandoned) 2008- Google’s V8 Engine 2009- Node.js created 2009- ECMAScript v5 2010- Test262 created 2011- ISO/IEC 16262:2011 2011- ECMAScript v5.1 History of JavaScript
8
2013 – Java 8’s JavaScript Engine (Nashorn) 201? ECMAScript v6 Only strict mode Incompatible syntax Classes Getters/Setters Tamper proof objects Block Scoping Future of JavaScript
9
Adobe, Mozilla, Microsoft Later came IBM, Google, Apple, Opera, Dojo, and Company 100. ECMAScript Committee
10
CodenameBrowserTest262 Fail Percent JscriptMicrosoft Internet Explo. 95.2% SpiderMonkeyFirefox1.5% FutharkOpera0.1% V8Chrome0.1% Implementations Test262 really important
11
End of line semicolons optional Automatically inserted by compiler Excess whitespace and comments are discarded during lexical analysis Strings can be defined by ' or " Multiline Strings possible with \ Grammar
12
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
13
var - has functional scoping const null undefined let has block scoping ( ECMAScript v6 ) let and const to replace var Usable Types
14
Undefined - primitive value used when a variable has not been assigned a value Null - no value Boolean – true/false Number - double-precision 64-bit NaN, Positive Infinity, Negative Infinity IEEE 754 String - UTF-16 Object runtime system performs automatic type conversion as needed 1+true=2, null + false = 0, null != false, null == undefined Type coercion – new Boolean(true); Internal Types
15
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
16
Flow Control - Sequencing function test(){ for( var i = 0; i<10; i++){ //doSomething; } return i; } result is 10
17
if ( Expression ) Statement else Statement if ( Expression ) Statement SwitchStatement: switch ( Expression ) CaseBlock CaseBlock: { CaseClause } { CaseClause DefaultClause CaseClause } CaseClause: case Expression : StatementList Default Clause: default : StatementList with( Expression ) Statement LogicalORExpression ? AssignmentExpression : AssignmentExpression Flow Control – Selection
18
Simple Assignment: = Compound Assignment: op= *= /= %= += -= >= >>>= &= ^= |= Comma Operator (, ) Flow Control – Expression Evaluation
19
do Statement while ( Expression ); while ( Expression ) Statement for ( ExpressionNoIn ; Expression ; Expression ) Statement for ( var VarDeclaration ; Expression ; Expression ) Statement for ( LeftHandSideExpression in Expression ) Statement for ( var VariableDeclarationNoIn in Expression ) Statement label, break, continue, (throw, return, ‘normal’) Flow Control – Iteration
20
function Identifier ( ParameterList ) { FunctionBody } function ( ParameterList ) { FunctionBody } function square(y){ this.rslt = y*y; } var x = new square(5); x.rslt; var square = new Function("a", "b", "return a*b") Flow Control – Procedural Abstraction var x = function(y) { return y * y; }; x(5); function square(y){ return y*y; } square(5); var Math = { square: function(y){ return y*y } Math.square(5);
21
Object Properties Flow Control – Procedural Abstraction Object.defineProperty(o, "a", { value : 37, writable : true, enumerable : true, configurable : true, get : function(){ return bValue; }, set : function(newValue){ bValue = newValue; } });
22
No optimization for Tail Call Recursion No concurrency setTimeout(func, delay, [params]) setInterval() new Worker(“something.js”) Flow Control – Recursion/Concurrency
23
try / catch try / finally try / catch / finally try { Code } catch ( Identifier ) {Code} finally {Code} throw Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError and URIError Flow Control – Exception Handling
24
Global - variables that are not declared but are referenced are automatically global Eval Strict Mode- cannot return variables Creates a new binding Function function x(){t = 5}; x(); console.log(t) //5 function x(){var t = 5}; x(); console.log(t) //undef Execution Context
25
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
26
function Person(){} function Ninja(){} Ninja.prototype = new Person(); (new Ninja()) instanceof Person var o = new Object(); o.[[Prototype]] = Foo.prototype; o.Foo(); Prototype Based Inheritance
27
Number parseInt() parseFloat() parseInt() isNaN() ifFinite() eval() Library Math JSON Date RegExp Special Characters decodeURI encodeURI Built-in Functions
28
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
29
user defined types generics NONE!
30
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
31
new Array([item1, item2, …]) new Array(len) Keys can be integers or strings Can be treated as: Arrays, Queues, Stacks, Priority Queues, Set No bounds arr[arr.length] = I; Arrays
32
push pop reverse sort sort(function) shift slice splice unshift indexOf every lastIndexOf some(function) forEach(function) map(function) filter(function) reduce(function) reduceRight(function) Array Operations
33
x = 42; // creates the property x on the global object var y = 43; // declares a new variable, y myobj = {}; myobj.h = 4; // creates property h on myobj myobj.k = 5; // creates property k on myobj delete x; // returns true (x is a property of the global object and can be deleted) delete y; // returns false (delete doesn't affect variable names) delete Math.PI; // returns false (delete doesn't affect certain predefined properties) delete myobj.h; // returns true (user-defined properties can be deleted) with(myobj) { delete k; // returns true (equivalent to delete myobj.k) } delete myobj; // returns true delete
34
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
35
bind() is powerful x.bind(this); call() – allows calling inner functions with current bindings toString() Built-in Function Functions
36
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
37
Floating point arithmetic IEEE 754 0.1 + 0.2 !== 0.3 A bad choice All implementations see to behave differently Code not portable Accidental scoping Global variables var a = 0 || "4"; a = "4“ Scope hoisting eval() Quirks
38
Introduction Data Types Flow Control Inheritance/Built-in Functions User defined types, Generics Arrays Function methods Quirks Comparison
39
JavaScriptJavaCGo Type Loosely Typed Strongly Typed Inheritance PrototypalClassical Automatic Multiple Inheritance No Yes Generics NoYesNo Pointers NoYesNoYes Closures YesNo Yes Exceptions Yes NoBuilt-in Threads NoYes Garbage Collection Yes NoYes Semi-Colon Optional YesNo Yes Like JavaScript 100%30% 40%
40
“Java and Javascript are similar like Car and Carpet are similar.” Greg Hewgill
41
www.ecma-international.org /publications/files/ECMA-ST/Ecma-262.pdf References
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.