JavaScript
Weird and Amazing
Compiled by:
Saad Abbasi
S. M. Taha
•Its one of the most powerful and highly in-demand programming language.
•Choice of Google, Microsoft, Linux Foundation, 10Gen and Mozilla
JavaScript – Weird and Amazing
Introduction:
Latest Trends in Programming Languages
- According to data provided by one of the largest social networks for programmers and software development platform "Github", Javascript is leading programming language.
- According to a survey conducted by "stackoverflow", Javascript is market leader in most of the domains in industry.
JavaScript – Weird and Amazing
Similarity b/w Java and JavaScript
JavaScript – Weird and Amazing
JavaScript === Java
if and only if
Car === Carpet.
Some of you may be interested in
•It was written by a guy named Brandon Eiac within just 7 or 10 days in 1995
•For browsers? Not Intentionally but eventually
•First Browser to adopt JavaScript was Netscape (Mozilla).
•Influenced greatly by Scheme programming language.
•Different JavaScript.
JavaScript – Weird and Amazing
History of JavaScript:
- Almost everywhere.
- Competing Java, Python and Ruby like languages.
- Not just web, but every platform.
- JQuery, Angular, Node, Express, Kraken, Ionic and Electron are just JavaScript.
JavaScript – Weird and Amazing
Where is it now? (Why should you learn it?)
JavaScript – Weird and Amazing
SAAD ABBASI S. M. TAHA
But why us?
- Learning Javascript and its frameworks including NodeJS, Angular2, JQuery.
- Follow me and my projects github.com/SMTaha.
- Member of Karachi.js.
- Certificate of completion in HTML, CSS and JavaScript from The Hong Kong University of Science and Technology
- Full Stack MEAN & MEA2N Developer.
- Follow me and my projects github.com/isaadabbasi.
- Started off with Java, but …
- Member of Karachi.js.
- Data Visualization using socket.IO & D3.
- Basic to Advanced syntax.
- Deep dive into core logic.
- Complex problem solving.
- Interview questions.
- Word Alerts.
- Weird and Amazing parts.
JavaScript – Weird and Amazing
What are we going to cover
At the end of the course you will be able to understand codes like
JavaScript – Weird and Amazing
function timebomb(){
var _arr = [];
setTimeout(function(){
for (var i=0; i<3; i++){
_arr.push((function(j){
return function(){
console.log( j );
}
}(i)))
}
}, 1000);
return _arr == [] ? null : _arr;
}
console.log(timebomb());
function mess(){
var array = [];
for(var i=0; i<5; i++){
array.push(
(function(j){
return function(){
console.log(j);
}
}(i))
)
}
return array;
}
for (i in mess())
console.log( mess()[i]() );
JavaScript – Weird and Amazing
SO,
LETS GET STARTED
JavaScript – Weird and Amazing
Understanding the Nature of JS
Synchronous
&
Single Theraded
- One at a time
JavaScript – Weird and Amazing
Synchronous
- JavaScript is Single Threaded.
- Only one command at a time.
JavaScript – Weird and Amazing
Single Threaded
SYNTAX PARSERS,
EXECUTION CONTEXT AND
LEXICAL ENVIORNMENTS
JavaScript – Weird and Amazing
SYNTAX PARSER:
A PROGRAM THAT READS YOUR CODE AND DETERMINES WHAT IT DOES AND IF ITS GRAMMAR IS VALID
Your code isn't magic. Someone else wrote a program to translate it for computer.
JavaScript – Weird and Amazing
LEXICAL ENVIRONMENT:
WHERE SOMETHING SITS PHYSICALLY IN THE CODE YOU WRITE
'Lexical' means 'having to do with words or grammar'. A lexical environment exist in programming language in which where you write something is important.
JavaScript – Weird and Amazing
EXECUTION CONTEXT:
A WRAPPER TO HELP MANAGE THE CODE THAT IS RUNNING
There are lots of lexical environments. Which one is currently running is managed via execution contexts. It can contain things beyond what you've written in your code.
JavaScript – Weird and Amazing
Its important!
NAME/VALUE PAIRS AND OBJECTS
JavaScript – Weird and Amazing
NAME/VALUE PAIR:
A NAME WHICH MAPS TO A UNIQUE VALUE
The name may be defined more than once, but only can have one value in any given context.
That value may be more name/value pairs.
JavaScript – Weird and Amazing
OBJECT:
A COLLECTION OF NAME VALUE PAIRS
The simplest definition when talking about Javascript.
JavaScript – Weird and Amazing
THE GLOBAL ENVIRONMENT AND THE GLOBAL OBJECT
JavaScript – Weird and Amazing
GLOBAL
- "Not Inside a Function
JavaScript – Weird and Amazing
THE EXECUTION CONTEXT:
CREATION AND HOISTING
JavaScript – Weird and Amazing
JAVASCRIPT AND 'UNDEFINED'
JavaScript – Weird and Amazing
FUNCTION INVOCATION
AND
THE EXECUTION STACK
JavaScript – Weird and Amazing
INVOCATION:
RUNNING A FUNCTION
In Javascript, by using parenthesis ()
JavaScript – Weird and Amazing
EXECUTION STACK
FUNCTION, CONTEXT
AND
VARIABLE ENVIRONMENTS
JavaScript – Weird and Amazing
VARIABLE ENVIRONMENT:
WHERE THE VARIABLES LIVE
And how they relate to each other in memory
JavaScript – Weird and Amazing
THE SCOPE CHAIN
JavaScript – Weird and Amazing
JavaScript
By Syed M. Taha
JavaScript
JavaScript - The Weird Parts.
- 266