SlideShare a Scribd company logo
The JavaScript
Interpreter, Interpreted
@marthakelly
Software’s Primary Technical Imperative is
_________________
Software’s Primary Technical Imperative is
managing complexity
JavaScript is (usually) interpreted
Source Code >> Parser >> AST >> Bytecode >>
Machine Code
JavaScript is...really wonderful
● (nearly) everything is an object
● functions are first class objects
○ variables
○ object methods
○ arrays
○ passed as arguments
○ returned as values
To understand JavaScript you must understand
how the JavaScript creates function objects.
Function Objects have two stages
1. Creation
a. << magic happens!>>
b. determines scope and context
2. Execution
a. function is run
It’s all about (Execution) Context
All JavaScript code is executed through an
execution context
● Global
● Function
● Eval
Execution Context Stacks
var kitty = function() {
console.log(“kitty”);
}
var hello = function() {
console.log(“hello”);
kitty();
}
hello();
Stacks:
[[ Function Kitty Context ]]
[[ Function Hello Context ]]
[[ Global Execution Context ]]
Execution Context is an “object”
var executionContext = {
variableObject: {},
scopeChain: {},
this: {}
}
var executionContext = {
variableObject: {
arguments: {
parameterName: argumentValue;
},
functionName: pointer;*
variableName: undefined;*
}
...
var kitten = function() {
console.log(mew);
var mew = 'Mew!';
}
// is interpreted as
var kitten = function() {
var mew = undefined;
console.log(mew);
mew = 'Mew!';
}
kitten() // undefined
The properties created on the Variable object
for local variable declarations initially
assigned as undefined.
Despite JavaScript’s C-like syntax, JavaScript
does not have block level scoping.
JavaScript has function scope (lexical scoping)
Scope
Scope chain
functions have the scope chain of the execution context in
which they are created assigned to their internal [[scope]]
property.
+------------------------------+
| global variable obj |
+------------------------------+
^
|
+-----------------------------+
| variable obj for outer call |
+-----------------------------+
^
|
+-----------------------------+
| variable obj for inner call |
+-----------------------------+
Resolving Identifiers
JavaScript traverses up the scope chain, moving
locally to globally.
Note:
Identifiers are resolved against the scope chain. ECMA
262 categorizes this as a keyword rather than an
identifier.
“this”
this holds a reference to the object that the
function is being applied to.
This doesn't necessarily means that this will equal
the object where the function is stored.
GO AND FIND BEE AND PUPPYCAT ON YOUTUBE NOW
var bee = {name: 'Bee'};
var puppycat = {name: 'PuppyCat'};
bee.sayHello = function(){
return "Hi, I'm " + this.name;
}
puppycat.sayHello = bee.sayHello;
var bee = {name: 'Bee'};
var puppycat = {name: 'PuppyCat'};
bee.sayHello = function(){
return "Hi, I'm " + this.name;
}
puppycat.sayHello = bee.sayHello;
// Hi, I’m PuppyCat
“this”
● top level function
○ global object**
● method
○ the object it’s applied to
● constructor
○ the created object
Omg, Closures
A closure is created when a function
remembers the variables in its scope when it
was created.
var findTheKitten = function() {
var secret = “under the bed”;
return {
guess: function(guess) {
if (guess === secret) {
console.log(“YUP”);
} else {
console.log(“NOPE”);
}
}
}
}
var game = findTheKitten();
game.guess(“in the closet”); // NOPE
game.guess(“under the bed”); // YUP
Hopefully now you know more about
how JS works
Thanks, everyone!
@marthakelly

More Related Content

What's hot (20)

PDF
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
PDF
GPars For Beginners
Matt Passell
 
PDF
Groovy and Grails talk
desistartups
 
PDF
NS2: AWK and GNUplot - PArt III
Ajit Nayak
 
PDF
Graphql with Flamingo
i-love-flamingo
 
PDF
Ns2: Introduction - Part I
Ajit Nayak
 
PDF
Ns2: OTCL - PArt II
Ajit Nayak
 
PDF
Reactive Programming Patterns with RxSwift
Florent Pillet
 
PDF
Grailsでドメイン駆動設計を実践する時の勘所
Takuma Watabiki
 
PDF
Functional Programming with JavaScript
Mark Shelton
 
PDF
Multi qubit entanglement
Vijayananda Mohire
 
PPT
jimmy hacking (at) Microsoft
Jimmy Schementi
 
PDF
201801 CSE240 Lecture 13
Javier Gonzalez-Sanchez
 
PDF
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
PDF
An Introduction to Reactive Cocoa
SmartLogic
 
PDF
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Igalia
 
PPT
Threads
Kavita Kanojiya
 
PDF
Tracing and awk in ns2
Pradeep Kumar TS
 
PDF
Functional Reactive Programming - RxSwift
Rodrigo Leite
 
PPTX
FunctionalJS - George Shevtsov
Georgiy Shevtsov
 
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
GPars For Beginners
Matt Passell
 
Groovy and Grails talk
desistartups
 
NS2: AWK and GNUplot - PArt III
Ajit Nayak
 
Graphql with Flamingo
i-love-flamingo
 
Ns2: Introduction - Part I
Ajit Nayak
 
Ns2: OTCL - PArt II
Ajit Nayak
 
Reactive Programming Patterns with RxSwift
Florent Pillet
 
Grailsでドメイン駆動設計を実践する時の勘所
Takuma Watabiki
 
Functional Programming with JavaScript
Mark Shelton
 
Multi qubit entanglement
Vijayananda Mohire
 
jimmy hacking (at) Microsoft
Jimmy Schementi
 
201801 CSE240 Lecture 13
Javier Gonzalez-Sanchez
 
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
An Introduction to Reactive Cocoa
SmartLogic
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Igalia
 
Tracing and awk in ns2
Pradeep Kumar TS
 
Functional Reactive Programming - RxSwift
Rodrigo Leite
 
FunctionalJS - George Shevtsov
Georgiy Shevtsov
 

Viewers also liked (9)

PPT
A Deeper look into Javascript Basics
Mindfire Solutions
 
PDF
Pedagogy.js
Martha Schumann
 
PPT
Array
mussawir20
 
PDF
Extending built in objects
Muhammad Ahmed
 
PPT
JavaScript Event Loop
Thomas Hunter II
 
PDF
Advanced Object-Oriented JavaScript
ecker
 
PDF
Node.js in action
Simon Su
 
PPTX
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
PPTX
JavaScript Event Loop
Designveloper
 
A Deeper look into Javascript Basics
Mindfire Solutions
 
Pedagogy.js
Martha Schumann
 
Array
mussawir20
 
Extending built in objects
Muhammad Ahmed
 
JavaScript Event Loop
Thomas Hunter II
 
Advanced Object-Oriented JavaScript
ecker
 
Node.js in action
Simon Su
 
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
JavaScript Event Loop
Designveloper
 
Ad

Similar to Js interpreter interpreted (20)

PDF
Javascript development done right
Pawel Szulc
 
PPTX
Object oriented java script
vivek p s
 
PDF
Pragmatic JavaScript
John Hann
 
PPT
Advanced JavaScript
Fu Cheng
 
PPTX
JavaScript- Functions and arrays.pptx
Megha V
 
PPTX
Javascript internals
Nir Noy
 
PPTX
oojs
Imran shaikh
 
ODP
JavaScript global object, execution contexts & closures
HDR1001
 
PPT
Basic Javascript
Bunlong Van
 
PPTX
JS
scandiweb
 
PDF
Javascript fundamentals for php developers
Chris Ramakers
 
PDF
Alessandro (cirpo) Cinelli - Dear JavaScript - Codemotion Berlin 2018
Codemotion
 
PPT
Javascript quiz. Questions to ask when recruiting developers.
Alberto Naranjo
 
PDF
JavaScript for real men
Ivano Malavolta
 
PPTX
JavaScript code academy - introduction
Jaroslav Kubíček
 
PDF
Dear JavaScript
Alessandro Cinelli (cirpo)
 
PDF
JavaScript
Ivano Malavolta
 
PDF
"this" in JavaScript
Martha Schumann
 
PDF
Scalable JavaScript
Ynon Perek
 
PDF
Javascript under the hood 1
Thang Tran Duc
 
Javascript development done right
Pawel Szulc
 
Object oriented java script
vivek p s
 
Pragmatic JavaScript
John Hann
 
Advanced JavaScript
Fu Cheng
 
JavaScript- Functions and arrays.pptx
Megha V
 
Javascript internals
Nir Noy
 
JavaScript global object, execution contexts & closures
HDR1001
 
Basic Javascript
Bunlong Van
 
Javascript fundamentals for php developers
Chris Ramakers
 
Alessandro (cirpo) Cinelli - Dear JavaScript - Codemotion Berlin 2018
Codemotion
 
Javascript quiz. Questions to ask when recruiting developers.
Alberto Naranjo
 
JavaScript for real men
Ivano Malavolta
 
JavaScript code academy - introduction
Jaroslav Kubíček
 
JavaScript
Ivano Malavolta
 
"this" in JavaScript
Martha Schumann
 
Scalable JavaScript
Ynon Perek
 
Javascript under the hood 1
Thang Tran Duc
 
Ad

Recently uploaded (20)

PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 

Js interpreter interpreted

  • 2. Software’s Primary Technical Imperative is _________________
  • 3. Software’s Primary Technical Imperative is managing complexity
  • 4. JavaScript is (usually) interpreted Source Code >> Parser >> AST >> Bytecode >> Machine Code
  • 5. JavaScript is...really wonderful ● (nearly) everything is an object ● functions are first class objects ○ variables ○ object methods ○ arrays ○ passed as arguments ○ returned as values
  • 6. To understand JavaScript you must understand how the JavaScript creates function objects.
  • 7. Function Objects have two stages 1. Creation a. << magic happens!>> b. determines scope and context 2. Execution a. function is run
  • 8. It’s all about (Execution) Context All JavaScript code is executed through an execution context ● Global ● Function ● Eval
  • 9. Execution Context Stacks var kitty = function() { console.log(“kitty”); } var hello = function() { console.log(“hello”); kitty(); } hello(); Stacks: [[ Function Kitty Context ]] [[ Function Hello Context ]] [[ Global Execution Context ]]
  • 10. Execution Context is an “object” var executionContext = { variableObject: {}, scopeChain: {}, this: {} }
  • 11. var executionContext = { variableObject: { arguments: { parameterName: argumentValue; }, functionName: pointer;* variableName: undefined;* } ...
  • 12. var kitten = function() { console.log(mew); var mew = 'Mew!'; } // is interpreted as var kitten = function() { var mew = undefined; console.log(mew); mew = 'Mew!'; } kitten() // undefined
  • 13. The properties created on the Variable object for local variable declarations initially assigned as undefined.
  • 14. Despite JavaScript’s C-like syntax, JavaScript does not have block level scoping. JavaScript has function scope (lexical scoping) Scope
  • 15. Scope chain functions have the scope chain of the execution context in which they are created assigned to their internal [[scope]] property. +------------------------------+ | global variable obj | +------------------------------+ ^ | +-----------------------------+ | variable obj for outer call | +-----------------------------+ ^ | +-----------------------------+ | variable obj for inner call | +-----------------------------+
  • 16. Resolving Identifiers JavaScript traverses up the scope chain, moving locally to globally. Note: Identifiers are resolved against the scope chain. ECMA 262 categorizes this as a keyword rather than an identifier.
  • 17. “this” this holds a reference to the object that the function is being applied to. This doesn't necessarily means that this will equal the object where the function is stored.
  • 18. GO AND FIND BEE AND PUPPYCAT ON YOUTUBE NOW
  • 19. var bee = {name: 'Bee'}; var puppycat = {name: 'PuppyCat'}; bee.sayHello = function(){ return "Hi, I'm " + this.name; } puppycat.sayHello = bee.sayHello;
  • 20. var bee = {name: 'Bee'}; var puppycat = {name: 'PuppyCat'}; bee.sayHello = function(){ return "Hi, I'm " + this.name; } puppycat.sayHello = bee.sayHello; // Hi, I’m PuppyCat
  • 21. “this” ● top level function ○ global object** ● method ○ the object it’s applied to ● constructor ○ the created object
  • 22. Omg, Closures A closure is created when a function remembers the variables in its scope when it was created.
  • 23. var findTheKitten = function() { var secret = “under the bed”; return { guess: function(guess) { if (guess === secret) { console.log(“YUP”); } else { console.log(“NOPE”); } } } } var game = findTheKitten(); game.guess(“in the closet”); // NOPE game.guess(“under the bed”); // YUP
  • 24. Hopefully now you know more about how JS works Thanks, everyone! @marthakelly