SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
JavaScript
The good, bad and awful parts
Moamen Mokhtar Usama Elnily
September 17, 2013
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Outline
1 Intro
2 Functions
3 Arrays
4 Asyncrounus Javascript
5 Awful and bad parts
6 References
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Brief History
Facts about JS
Outline
1 Intro
2 Functions
3 Arrays
4 Asyncrounus Javascript
5 Awful and bad parts
6 References
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Brief History
Facts about JS
What is Javascript
The world most missunderstood programming language
(Neither Java nor Script!)
Lots of design errors.
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Brief History
Facts about JS
History
In 1992, James Gosling and java.
Netscape (Berndan Eich) and LiveScript.
Sun, Netscape and JavaScript.
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Brief History
Facts about JS
Javascript the language
Load and go delivery.
Loose typing.
Objects as general containers.
Prototypal inheritance.
Lambda.
Linkage through global variables.
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Brief History
Facts about JS
Facts about JS
NaN
NaN === NaN
==
’1’ == 1
” == false
typeof
typeof ”help”.toString;
for .. in
obj.
obj[’ ’]
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Outline
1 Intro
2 Functions
3 Arrays
4 Asyncrounus Javascript
5 Awful and bad parts
6 References
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Function definition
var foo = function();
function foo ();
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Augmenting
Function.prototype.method = function(name , func)
{
this.prototype[name] = func;
return this;
};
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Scope I
No block Scope.
Hoisting.
foo (); // not visible
bar (); // visible
var foo = function (){
...
};
function bar (){
...
};
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Scope II
function foo (){
function bar() {
return 3;
}
return bar ();
function bar() {
return 8;
}
}
alert(foo ());
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Scope III
function foo (){
var bar = function () {
return 3;
};
return bar ();
var bar = function () {
return 8;
};
}
alert(foo ());
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Scope IV
alert(foo ());
function foo (){
var bar = function () {
return 3;
};
return bar ();
var bar = function () {
return 8;
};
}
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Scope V
function foo (){
return bar ();
var bar = function () {
return 3;
};
var bar = function () {
return 8;
};
}
alert(foo ());
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Scope VI
var foo = 1;
function bar() {
if (!foo) {
var foo = 10;
}
alert(foo);
}
bar ();
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Arguments
An array-like variable.
Contains all of the arguments of the functions.
Doesn’t have all the functions of arrays except length().
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Apply and Call function invocation
Difference between apply and call.
theFunction.apply(valueForThis , arrayOfArgs)
theFunction.call(valueForThis , arg1 , arg2 , ...)
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Closure
var myObject = function ( ) {
var value = 0;
return {
increment: function (inc) {
value += typeof inc === ’number ’ ? inc : 1;
},
getValue: function ( ) {
return value;
}
}
}( );
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Curry
Function.method(’curry ’, function ( ) {
var slice = Array.prototype.slice ,
args = slice.apply(arguments),
that = this;
return function ( ) {
return that.apply(null ,
args.concat(slice.apply(arguments )));
};
});
Creates closure to hold arguments of the outer function to be
used in the inner function.
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Memoization I
var memoizer = function (memo , fundamental) {
var shell = function (n) {
var result = memo[n];
if (typeof result !== ’number ’) {
result = fundamental(shell , n);
memo[n] = result;
}
return result;
};
return shell;
};
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Function definition
Augmenting
Scope
Arguments
Apply vs. Call
Closure
Curry
Memoization
Memoization II
var fibonacci = memoizer ([0, 1],
function (shell , n) {
return shell(n - 1) + shell(n - 2);
});
var factorial = memoizer ([1, 1],
function (shell , n) {
return n * shell(n - 1);
});
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Important methods
Outline
1 Intro
2 Functions
3 Arrays
4 Asyncrounus Javascript
5 Awful and bad parts
6 References
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Important methods
Important methods
array.slice(start, end )
It makes a copy of a portion of the array starting from start to
end.
array.splice(start, deleteCount, item...)
The splice method removes elements from an array, replacing
them with new items.
It is different than delete as delete will replace the deleted
value with undefined
array.sort(comparefn )
The default sort function converts the array entries into strings
and sort lexicographically!.
It is provided with the sorting function (like comparable
objects in java).
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Why using async. functions
Sometimes-async functions
Throwing errors from callbacks
Outline
1 Intro
2 Functions
3 Arrays
4 Asyncrounus Javascript
5 Awful and bad parts
6 References
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Why using async. functions
Sometimes-async functions
Throwing errors from callbacks
Using async. functions
Prefered with discontinous events to prevent frozen clients.
What is a callback?
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Why using async. functions
Sometimes-async functions
Throwing errors from callbacks
for(vari =1;i <=3;i++){
setTimeout(function (){ console.log(i);} ,0);
};
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Why using async. functions
Sometimes-async functions
Throwing errors from callbacks
The devil is in the details
Javascript is single threaded.
Meet the queue.
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Why using async. functions
Sometimes-async functions
Throwing errors from callbacks
Sometimes-async functions I
Functions that are async sometimes, but not at other times.
Example: Async functions with caching.
var socketsCache ={};
function openWebSocket(serverAddress ,callback ){
var socket;
if(serverAddress in webSocketCache ){
socket=webSocketCache [serverAddress ];
if(socket.readyState === WebSocket.OPEN ){
callback ();
}
....
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Why using async. functions
Sometimes-async functions
Throwing errors from callbacks
Sometimes-async functions II
}else{
socket=newWebSocket(serverAddress );
webSocketCache [serverAddress ]= socket;
....
};
return socket;
};
var socket=openWebSocket(url ,function (){
....
});
....
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Why using async. functions
Sometimes-async functions
Throwing errors from callbacks
Throwing errors from callbacks
Can we catch error thrown from a callabck ?
try{
setTimeout(function (){
throw new Error(’Catch_me_if_you_can !’);
},0);
}catch(e){
console.error(e);
}
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Outline
1 Intro
2 Functions
3 Arrays
4 Asyncrounus Javascript
5 Awful and bad parts
6 References
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Awful and bad parts I
global variables
A non-declared variable is considered global.
Semicolon insertion
return
{
status: true
};
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
Awful and bad parts II
Reserved Words
Use them within quotes.
Access with subscript
object = {case: value }; // illegal
object = {’case ’: value }; // ok
object.case = value; // illegal
object[’case ’] = value; // ok
Bitwise Operators
Very slow!
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
References
Outline
1 Intro
2 Functions
3 Arrays
4 Asyncrounus Javascript
5 Awful and bad parts
6 References
Moamen Mokhtar, Usama Elnily JavaScript
Intro
Functions
Arrays
Asyncrounus Javascript
Awful and bad parts
References
References
References
Douglas Crockford.
JavaScript: The Good Parts.
O’Reilly, 2008.
Trevor Burnham.
Async JavaScript.
The Pragmatic Programmers, 2012.
Moamen Mokhtar, Usama Elnily JavaScript

Mais conteúdo relacionado

Mais procurados

CppCat Checks OpenMW: Not All is Fine in the Morrowind Universe
CppCat Checks OpenMW: Not All is Fine in the Morrowind UniverseCppCat Checks OpenMW: Not All is Fine in the Morrowind Universe
CppCat Checks OpenMW: Not All is Fine in the Morrowind UniverseAndrey Karpov
 
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...PVS-Studio
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio
 
From Elixir to Akka (and back) - ElixirConf Mx 2017
From Elixir to Akka (and back) - ElixirConf Mx 2017From Elixir to Akka (and back) - ElixirConf Mx 2017
From Elixir to Akka (and back) - ElixirConf Mx 2017Agustin Ramos
 
Ad-hoc Runtime Object Structure Visualizations with MetaLinks
Ad-hoc Runtime Object Structure Visualizations with MetaLinks Ad-hoc Runtime Object Structure Visualizations with MetaLinks
Ad-hoc Runtime Object Structure Visualizations with MetaLinks ESUG
 
The Unicorn's Travel to the Microcosm
The Unicorn's Travel to the MicrocosmThe Unicorn's Travel to the Microcosm
The Unicorn's Travel to the MicrocosmAndrey Karpov
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...PVS-Studio
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Andrey Karpov
 
Analysis of the Trans-Proteomic Pipeline (TPP) project
Analysis of the Trans-Proteomic Pipeline (TPP) projectAnalysis of the Trans-Proteomic Pipeline (TPP) project
Analysis of the Trans-Proteomic Pipeline (TPP) projectPVS-Studio
 
A Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-StudioA Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-StudioAndrey Karpov
 
PVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 projectPVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 projectPVS-Studio
 
Python and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error densityPython and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error densityPVS-Studio
 
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgeChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgePVS-Studio
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality codeJack Fox
 
Re-analysis of Umbraco code
Re-analysis of Umbraco codeRe-analysis of Umbraco code
Re-analysis of Umbraco codePVS-Studio
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, SwiftYandex
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xAndrey Karpov
 
PVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio
 
__array_function__ conceptual design & related concepts
__array_function__ conceptual design & related concepts__array_function__ conceptual design & related concepts
__array_function__ conceptual design & related conceptsRalf Gommers
 
Navigating the wild seas of es6 modules
Navigating the wild seas of es6 modulesNavigating the wild seas of es6 modules
Navigating the wild seas of es6 modulesGil Tayar
 

Mais procurados (20)

CppCat Checks OpenMW: Not All is Fine in the Morrowind Universe
CppCat Checks OpenMW: Not All is Fine in the Morrowind UniverseCppCat Checks OpenMW: Not All is Fine in the Morrowind Universe
CppCat Checks OpenMW: Not All is Fine in the Morrowind Universe
 
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...
 
From Elixir to Akka (and back) - ElixirConf Mx 2017
From Elixir to Akka (and back) - ElixirConf Mx 2017From Elixir to Akka (and back) - ElixirConf Mx 2017
From Elixir to Akka (and back) - ElixirConf Mx 2017
 
Ad-hoc Runtime Object Structure Visualizations with MetaLinks
Ad-hoc Runtime Object Structure Visualizations with MetaLinks Ad-hoc Runtime Object Structure Visualizations with MetaLinks
Ad-hoc Runtime Object Structure Visualizations with MetaLinks
 
The Unicorn's Travel to the Microcosm
The Unicorn's Travel to the MicrocosmThe Unicorn's Travel to the Microcosm
The Unicorn's Travel to the Microcosm
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
Analysis of the Trans-Proteomic Pipeline (TPP) project
Analysis of the Trans-Proteomic Pipeline (TPP) projectAnalysis of the Trans-Proteomic Pipeline (TPP) project
Analysis of the Trans-Proteomic Pipeline (TPP) project
 
A Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-StudioA Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-Studio
 
PVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 projectPVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 project
 
Python and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error densityPython and Ruby implementations compared by the error density
Python and Ruby implementations compared by the error density
 
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgeChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality code
 
Re-analysis of Umbraco code
Re-analysis of Umbraco codeRe-analysis of Umbraco code
Re-analysis of Umbraco code
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-x
 
PVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - Continuation
 
__array_function__ conceptual design & related concepts
__array_function__ conceptual design & related concepts__array_function__ conceptual design & related concepts
__array_function__ conceptual design & related concepts
 
Navigating the wild seas of es6 modules
Navigating the wild seas of es6 modulesNavigating the wild seas of es6 modules
Navigating the wild seas of es6 modules
 

Semelhante a Java script good_bad_awful

Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jscacois
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: ServersidenessWebExpo
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8Talha Ocakçı
 
Event driven javascript
Event driven javascriptEvent driven javascript
Event driven javascriptFrancesca1980
 
Event driven javascript
Event driven javascriptEvent driven javascript
Event driven javascriptFrancesca1980
 
"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta Semenistyi"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta SemenistyiBinary Studio
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Reactive Access to MongoDB from Scala
Reactive Access to MongoDB from ScalaReactive Access to MongoDB from Scala
Reactive Access to MongoDB from ScalaHermann Hueck
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsPiotr Pelczar
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTim Berglund
 
Test First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTest First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTim Berglund
 
Java coding pitfalls
Java coding pitfallsJava coding pitfalls
Java coding pitfallstomi vanek
 
JavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxJavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxRAHITNATH
 

Semelhante a Java script good_bad_awful (20)

Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Event driven javascript
Event driven javascriptEvent driven javascript
Event driven javascript
 
Event driven javascript
Event driven javascriptEvent driven javascript
Event driven javascript
 
"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta Semenistyi"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta Semenistyi
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Reactive Access to MongoDB from Scala
Reactive Access to MongoDB from ScalaReactive Access to MongoDB from Scala
Reactive Access to MongoDB from Scala
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in Grails
 
Test First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTest First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in Grails
 
Java coding pitfalls
Java coding pitfallsJava coding pitfalls
Java coding pitfalls
 
JavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptxJavaScript Multithread or Single Thread.pptx
JavaScript Multithread or Single Thread.pptx
 

Último

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Último (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Java script good_bad_awful

  • 1. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References JavaScript The good, bad and awful parts Moamen Mokhtar Usama Elnily September 17, 2013 Moamen Mokhtar, Usama Elnily JavaScript
  • 2. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Outline 1 Intro 2 Functions 3 Arrays 4 Asyncrounus Javascript 5 Awful and bad parts 6 References Moamen Mokhtar, Usama Elnily JavaScript
  • 3. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Brief History Facts about JS Outline 1 Intro 2 Functions 3 Arrays 4 Asyncrounus Javascript 5 Awful and bad parts 6 References Moamen Mokhtar, Usama Elnily JavaScript
  • 4. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Brief History Facts about JS What is Javascript The world most missunderstood programming language (Neither Java nor Script!) Lots of design errors. Moamen Mokhtar, Usama Elnily JavaScript
  • 5. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Brief History Facts about JS History In 1992, James Gosling and java. Netscape (Berndan Eich) and LiveScript. Sun, Netscape and JavaScript. Moamen Mokhtar, Usama Elnily JavaScript
  • 6. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Brief History Facts about JS Javascript the language Load and go delivery. Loose typing. Objects as general containers. Prototypal inheritance. Lambda. Linkage through global variables. Moamen Mokhtar, Usama Elnily JavaScript
  • 7. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Brief History Facts about JS Facts about JS NaN NaN === NaN == ’1’ == 1 ” == false typeof typeof ”help”.toString; for .. in obj. obj[’ ’] Moamen Mokhtar, Usama Elnily JavaScript
  • 8. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Outline 1 Intro 2 Functions 3 Arrays 4 Asyncrounus Javascript 5 Awful and bad parts 6 References Moamen Mokhtar, Usama Elnily JavaScript
  • 9. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Function definition var foo = function(); function foo (); Moamen Mokhtar, Usama Elnily JavaScript
  • 10. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Augmenting Function.prototype.method = function(name , func) { this.prototype[name] = func; return this; }; Moamen Mokhtar, Usama Elnily JavaScript
  • 11. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Scope I No block Scope. Hoisting. foo (); // not visible bar (); // visible var foo = function (){ ... }; function bar (){ ... }; Moamen Mokhtar, Usama Elnily JavaScript
  • 12. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Scope II function foo (){ function bar() { return 3; } return bar (); function bar() { return 8; } } alert(foo ()); Moamen Mokhtar, Usama Elnily JavaScript
  • 13. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Scope III function foo (){ var bar = function () { return 3; }; return bar (); var bar = function () { return 8; }; } alert(foo ()); Moamen Mokhtar, Usama Elnily JavaScript
  • 14. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Scope IV alert(foo ()); function foo (){ var bar = function () { return 3; }; return bar (); var bar = function () { return 8; }; } Moamen Mokhtar, Usama Elnily JavaScript
  • 15. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Scope V function foo (){ return bar (); var bar = function () { return 3; }; var bar = function () { return 8; }; } alert(foo ()); Moamen Mokhtar, Usama Elnily JavaScript
  • 16. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Scope VI var foo = 1; function bar() { if (!foo) { var foo = 10; } alert(foo); } bar (); Moamen Mokhtar, Usama Elnily JavaScript
  • 17. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Arguments An array-like variable. Contains all of the arguments of the functions. Doesn’t have all the functions of arrays except length(). Moamen Mokhtar, Usama Elnily JavaScript
  • 18. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Apply and Call function invocation Difference between apply and call. theFunction.apply(valueForThis , arrayOfArgs) theFunction.call(valueForThis , arg1 , arg2 , ...) Moamen Mokhtar, Usama Elnily JavaScript
  • 19. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Closure var myObject = function ( ) { var value = 0; return { increment: function (inc) { value += typeof inc === ’number ’ ? inc : 1; }, getValue: function ( ) { return value; } } }( ); Moamen Mokhtar, Usama Elnily JavaScript
  • 20. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Curry Function.method(’curry ’, function ( ) { var slice = Array.prototype.slice , args = slice.apply(arguments), that = this; return function ( ) { return that.apply(null , args.concat(slice.apply(arguments ))); }; }); Creates closure to hold arguments of the outer function to be used in the inner function. Moamen Mokhtar, Usama Elnily JavaScript
  • 21. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Memoization I var memoizer = function (memo , fundamental) { var shell = function (n) { var result = memo[n]; if (typeof result !== ’number ’) { result = fundamental(shell , n); memo[n] = result; } return result; }; return shell; }; Moamen Mokhtar, Usama Elnily JavaScript
  • 22. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Function definition Augmenting Scope Arguments Apply vs. Call Closure Curry Memoization Memoization II var fibonacci = memoizer ([0, 1], function (shell , n) { return shell(n - 1) + shell(n - 2); }); var factorial = memoizer ([1, 1], function (shell , n) { return n * shell(n - 1); }); Moamen Mokhtar, Usama Elnily JavaScript
  • 23. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Important methods Outline 1 Intro 2 Functions 3 Arrays 4 Asyncrounus Javascript 5 Awful and bad parts 6 References Moamen Mokhtar, Usama Elnily JavaScript
  • 24. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Important methods Important methods array.slice(start, end ) It makes a copy of a portion of the array starting from start to end. array.splice(start, deleteCount, item...) The splice method removes elements from an array, replacing them with new items. It is different than delete as delete will replace the deleted value with undefined array.sort(comparefn ) The default sort function converts the array entries into strings and sort lexicographically!. It is provided with the sorting function (like comparable objects in java). Moamen Mokhtar, Usama Elnily JavaScript
  • 25. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Why using async. functions Sometimes-async functions Throwing errors from callbacks Outline 1 Intro 2 Functions 3 Arrays 4 Asyncrounus Javascript 5 Awful and bad parts 6 References Moamen Mokhtar, Usama Elnily JavaScript
  • 26. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Why using async. functions Sometimes-async functions Throwing errors from callbacks Using async. functions Prefered with discontinous events to prevent frozen clients. What is a callback? Moamen Mokhtar, Usama Elnily JavaScript
  • 27. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Why using async. functions Sometimes-async functions Throwing errors from callbacks for(vari =1;i <=3;i++){ setTimeout(function (){ console.log(i);} ,0); }; Moamen Mokhtar, Usama Elnily JavaScript
  • 28. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Why using async. functions Sometimes-async functions Throwing errors from callbacks The devil is in the details Javascript is single threaded. Meet the queue. Moamen Mokhtar, Usama Elnily JavaScript
  • 29. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Why using async. functions Sometimes-async functions Throwing errors from callbacks Sometimes-async functions I Functions that are async sometimes, but not at other times. Example: Async functions with caching. var socketsCache ={}; function openWebSocket(serverAddress ,callback ){ var socket; if(serverAddress in webSocketCache ){ socket=webSocketCache [serverAddress ]; if(socket.readyState === WebSocket.OPEN ){ callback (); } .... Moamen Mokhtar, Usama Elnily JavaScript
  • 30. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Why using async. functions Sometimes-async functions Throwing errors from callbacks Sometimes-async functions II }else{ socket=newWebSocket(serverAddress ); webSocketCache [serverAddress ]= socket; .... }; return socket; }; var socket=openWebSocket(url ,function (){ .... }); .... Moamen Mokhtar, Usama Elnily JavaScript
  • 31. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Why using async. functions Sometimes-async functions Throwing errors from callbacks Throwing errors from callbacks Can we catch error thrown from a callabck ? try{ setTimeout(function (){ throw new Error(’Catch_me_if_you_can !’); },0); }catch(e){ console.error(e); } Moamen Mokhtar, Usama Elnily JavaScript
  • 32. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Outline 1 Intro 2 Functions 3 Arrays 4 Asyncrounus Javascript 5 Awful and bad parts 6 References Moamen Mokhtar, Usama Elnily JavaScript
  • 33. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Awful and bad parts I global variables A non-declared variable is considered global. Semicolon insertion return { status: true }; Moamen Mokhtar, Usama Elnily JavaScript
  • 34. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References Awful and bad parts II Reserved Words Use them within quotes. Access with subscript object = {case: value }; // illegal object = {’case ’: value }; // ok object.case = value; // illegal object[’case ’] = value; // ok Bitwise Operators Very slow! Moamen Mokhtar, Usama Elnily JavaScript
  • 35. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References References Outline 1 Intro 2 Functions 3 Arrays 4 Asyncrounus Javascript 5 Awful and bad parts 6 References Moamen Mokhtar, Usama Elnily JavaScript
  • 36. Intro Functions Arrays Asyncrounus Javascript Awful and bad parts References References References Douglas Crockford. JavaScript: The Good Parts. O’Reilly, 2008. Trevor Burnham. Async JavaScript. The Pragmatic Programmers, 2012. Moamen Mokhtar, Usama Elnily JavaScript