SlideShare a Scribd company logo
1 of 24
Things that every JS
developer should know
Rachel Appel | JetBrains
http://rachelappel.com
rachel@rachelappel.com
@RachelAppel
What’s in this talk?
• Basic things are important for every JS developer
• So are some advanced things
It does. Its origins
are from JS.
Seriously
WTF?!?
LOL WAT?!?
Data Types
• There really are data types in JavaScript!
• But does JavaScript care?
• Value types (aka primitives)
• Number, string, Boolean, null, undefined, object, symbol
• Reference types
• Objects and arrays
Functions & Scope
Callable objects
Key-value dictionaries under the hood
Global
<script src="1.js">
var a, b, c
<script src="2.js">
var a, b, c
<script src="3.js">
var a, b, c
<script src="4.js">
var a, b, c
Window object
Global namespace pollution
Module/Module Reveal Pattern
var vs let
• var is function scoped
• Can declare globally or locally
• let is block scoped
• Declarations are limited in scope
to the block
A closure is a special kind of object that combines
two things: a function, and the environment in
which that function was created. The environment
consists of any local variables that were in-scope
at the time that the closure was created.
Lexical scope: captures variables from parent
scopes
arrow functions and closures
• Arrows don’t create their own value for ‘this’
• They use the enclosing block
Inheritance
• Prototype-base inheritance, changing the prototype of an object.
• ES6 classes and extends
• defineproperty
•
Arrays
• Is it a true Array?
• No dimensions, per se
• No out of bounds errors
• typeof calls it an object
• [] vs Array
== ===
Smooth Operators
!= !==
Truthy values
'false' (quoted false)
'0' (quoted zero)
() (empty functions)
[] (empty arrays)
{} (empty objects)
All other values
Falsey values
false
0 (zero)
'' (empty string)
null
undefined
NaN
Let's get to the truth of the matter
http://dorey.github.io/JavaScript-Equality-Table/
JavaScript
Equality
Table
Just what's up with this, anyway?
Typescript and this event obj
Sometimes when I'm writing JavaScript, I
just want to throw my hands up and yell
"This is bullshit!", but I can never remember
what "this" is referring to.
Strict mode [ES5]
• “use strict”
• No more accidental globals
• Must declare variables
• Assignment issues are no longer silent. They throw errors
• Function args with same name (yep, vanilla JS allows that)
Seems legit
var add = function() {
// do stuff
};
Yeah it’s legit! This is JavaScript!
console.log(add(4, 4, “cat”));
Look ma, no arguments!
Wait, what? Seriously?
Garbage collection
• Reachable
• Local variables and parameters of the current function.
• Variables and parameters for other functions on the current chain of nested
calls.
• Global variables.
• Internal stuff
Garbage collection
• The basic garbage collection algorithm is called “mark-and-sweep”.
• The following “garbage collection” steps are regularly performed:
• The garbage collector marks roots.
• It marks all references from them
• It visits marked objects and marks their references. (everything is tracked)
• Loop until unvisited refs happen
• All objects except marked ones are removed.
Typescript, compilers, transpilers, tools
• TypeScript
• Babel
• Webpack
• Typescript can validate JS code – just run them the compiler, like a
light linter
• Thank you!

More Related Content

What's hot

A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
mametter
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506
Vu Hung Nguyen
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-rails
vinicorp
 

What's hot (19)

A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-rails
 
Lua pitfalls
Lua pitfallsLua pitfalls
Lua pitfalls
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value Types
 
Coding in kotlin
Coding in kotlinCoding in kotlin
Coding in kotlin
 
Introduction to Kotlin JVM language
Introduction to Kotlin JVM languageIntroduction to Kotlin JVM language
Introduction to Kotlin JVM language
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
 
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
Object Oriented JavaScript - II
Object Oriented JavaScript - IIObject Oriented JavaScript - II
Object Oriented JavaScript - II
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 

Similar to Things that every JavaScript developer should know by Rachel Appel at FrontCon 2019

Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
mircodotta
 

Similar to Things that every JavaScript developer should know by Rachel Appel at FrontCon 2019 (20)

Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
Intermediate JavaScript
Intermediate JavaScriptIntermediate JavaScript
Intermediate JavaScript
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
Java script core
Java script coreJava script core
Java script core
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About Javascript
 
jQuery Objects
jQuery ObjectsjQuery Objects
jQuery Objects
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScript
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
 
Javascript omg!
Javascript omg!Javascript omg!
Javascript omg!
 
Introduction to JavaScript for APEX Developers - Module 1: JavaScript Basics
Introduction to JavaScript for APEX Developers - Module 1: JavaScript BasicsIntroduction to JavaScript for APEX Developers - Module 1: JavaScript Basics
Introduction to JavaScript for APEX Developers - Module 1: JavaScript Basics
 

More from DevClub_lv

More from DevClub_lv (20)

Fine-tuning Large Language Models by Dmitry Balabka
Fine-tuning Large Language Models by Dmitry BalabkaFine-tuning Large Language Models by Dmitry Balabka
Fine-tuning Large Language Models by Dmitry Balabka
 
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ..."Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
 
From 50 to 500 product engineers – data-driven approach to building impactful...
From 50 to 500 product engineers – data-driven approach to building impactful...From 50 to 500 product engineers – data-driven approach to building impactful...
From 50 to 500 product engineers – data-driven approach to building impactful...
 
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
 
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
 
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
 
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
 
SRE (service reliability engineer) on big DevOps platform running on the clou...
SRE (service reliability engineer) on big DevOps platform running on the clou...SRE (service reliability engineer) on big DevOps platform running on the clou...
SRE (service reliability engineer) on big DevOps platform running on the clou...
 
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
 
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
 
Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019
 
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
 
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
 
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
 
Bridging the gap between UX and development - A Storybook by Marko Letic at F...
Bridging the gap between UX and development - A Storybook by Marko Letic at F...Bridging the gap between UX and development - A Storybook by Marko Letic at F...
Bridging the gap between UX and development - A Storybook by Marko Letic at F...
 
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
 
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
 
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
 
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
 
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Things that every JavaScript developer should know by Rachel Appel at FrontCon 2019

  • 1. Things that every JS developer should know Rachel Appel | JetBrains http://rachelappel.com rachel@rachelappel.com @RachelAppel
  • 2. What’s in this talk? • Basic things are important for every JS developer • So are some advanced things
  • 3.
  • 4. It does. Its origins are from JS. Seriously WTF?!? LOL WAT?!?
  • 5. Data Types • There really are data types in JavaScript! • But does JavaScript care? • Value types (aka primitives) • Number, string, Boolean, null, undefined, object, symbol • Reference types • Objects and arrays
  • 6. Functions & Scope Callable objects Key-value dictionaries under the hood
  • 7. Global <script src="1.js"> var a, b, c <script src="2.js"> var a, b, c <script src="3.js"> var a, b, c <script src="4.js"> var a, b, c Window object Global namespace pollution Module/Module Reveal Pattern
  • 8. var vs let • var is function scoped • Can declare globally or locally • let is block scoped • Declarations are limited in scope to the block
  • 9. A closure is a special kind of object that combines two things: a function, and the environment in which that function was created. The environment consists of any local variables that were in-scope at the time that the closure was created.
  • 10. Lexical scope: captures variables from parent scopes
  • 11. arrow functions and closures • Arrows don’t create their own value for ‘this’ • They use the enclosing block
  • 12. Inheritance • Prototype-base inheritance, changing the prototype of an object. • ES6 classes and extends • defineproperty •
  • 13. Arrays • Is it a true Array? • No dimensions, per se • No out of bounds errors • typeof calls it an object • [] vs Array
  • 15. Truthy values 'false' (quoted false) '0' (quoted zero) () (empty functions) [] (empty arrays) {} (empty objects) All other values Falsey values false 0 (zero) '' (empty string) null undefined NaN Let's get to the truth of the matter
  • 17. Just what's up with this, anyway? Typescript and this event obj
  • 18. Sometimes when I'm writing JavaScript, I just want to throw my hands up and yell "This is bullshit!", but I can never remember what "this" is referring to.
  • 19. Strict mode [ES5] • “use strict” • No more accidental globals • Must declare variables • Assignment issues are no longer silent. They throw errors • Function args with same name (yep, vanilla JS allows that)
  • 20. Seems legit var add = function() { // do stuff }; Yeah it’s legit! This is JavaScript! console.log(add(4, 4, “cat”)); Look ma, no arguments! Wait, what? Seriously?
  • 21. Garbage collection • Reachable • Local variables and parameters of the current function. • Variables and parameters for other functions on the current chain of nested calls. • Global variables. • Internal stuff
  • 22. Garbage collection • The basic garbage collection algorithm is called “mark-and-sweep”. • The following “garbage collection” steps are regularly performed: • The garbage collector marks roots. • It marks all references from them • It visits marked objects and marks their references. (everything is tracked) • Loop until unvisited refs happen • All objects except marked ones are removed.
  • 23. Typescript, compilers, transpilers, tools • TypeScript • Babel • Webpack • Typescript can validate JS code – just run them the compiler, like a light linter

Editor's Notes

  1. https://www.youtube.com/watch?v=9ooYYRLdg_g REF v VAL types typeof operator, in particular, that it returns “object” for null. Special numeric values Infinity, -Infinity and NaN Null It is not a reference to a non-existing object. It is not a null pointer It is a special value that means: dunno, unknown, nothing, empty, nada
  2. let allows you to declare variables that are limited in scope to the block, statement,or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope
  3. A closure is a special kind of object that combines two things: a function, and the environment in which that function was created. The environment consists of any local variables that were in-scope at the time that the closure was created.
  4. In classic function expressions, the this keyword is bound to different values based on the context in which it is called. With arrow functions however, this is lexically bound. It means that it usesthis from the code that contains the arrow function.
  5. Arrays in JS aren't real arrays, they're phony no dimensions no out of bounds errors
  6. JavaScript has two sets of equality operators, equal to (==) and exactly equal to (===) and their counterparts in negation (!= and !==). The exactly equals works the way you expect. If the two operands are of the same type and have the same value, then exactly equals produces true and its negative partner (!==) produces false. The plain equals, OTOH, see different data types and attempts to coerce the values (it's called type coercion) by using a set of many overly complex rules. It's just not reasonable to memorize all these rules, especially if you are trying to create team standards from them. Therefore, since it's more accurate going with the exactly equals is the best option. Let's see some of this JS equality or non equality as the case may be, in action...[demo] THE TAKE AWAY: Use the === and !== opeartors as they give consistent and accurate results, more closely to what you might expect. console.log(0 == ''); console.log(0 === ''); console.log(0 == '0'); console.log(0 === '0'); console.log(false == 'false'); console.log(false === 'false'); console.log(false == '0'); console.log(false === '0'); console.log(false == undefined); console.log(false === undefined); console.log(false == null); console.log(false === null); console.log(null == undefined); console.log(null === undefined); console.log('\t\r\n' == 0); console.log('\t\r\n' === 0);
  7. What constitutes something falsy in JS? false. 0 (zero) "" (empty string) null undefined NaN (a special Number value meaning "Not a Number") All other values are truthy, including "0" (zero in quotes), "false" (false in quotes), empty functions, empty arrays, and empty objects.   Falsey: false 0 (zero) "" (empty string) null undefined NaN Truthy "false" (false in quotes) "0" (zero in quotes) () (empty functions) [] (empty arrays) {} (empty objects) All other values
  8. Many folks try to treat "this" the same way that it works in other languages and their notion of this is normally static and at the class level. JavaScript is different though, as this works based on the context of the calling code. Usually this belongs to the window, or global object, but it can also be the HTML element that has caused an event, for example, a button causing a click event. Then the function is owned by that source element and that element becomes this. To go a little deeper JavaScript functions run in an execution context that goes on the stack. The stack is an in memory storage location for variables and data. Functions are also values, and they're treated like objects/values. What this means is that each time another function runs, it gets pushed onto the stack and the context for "this" changes. That's unlike other languages where this is usually clearly defined. So the value of this depends on 2 things: What kind of code is executing? (global, function, or eval) and the calling code. ******* ES5 introduces the a way that you can set the value of "this" in a function, as the first argument of the call. Here in the IE console we have a function called saySomething that accepts a string and logs both this and the string to form a sentence about what this . Let's see it work. Now that I've run the function I can call it and make 'this' a programmer or a trekkie or katniss everdeen. Not that you'd wants strings to be this bit function saySomething(thing) { console.log(this + " says " + thing); } saySomething.call("A programmer", "Hello world"); saySomething.call("A Trekkie", "Live long and prosper."); saySomething.call("Katniss Everdeen", "May the odds be ever in your favor"); saySomething.call("A ghost", "Boooooooo!");
  9. Strict mode is part of the ECMAScript 5 standard. You can enable strict mode for a complete file or a single function: Complete file: put the line "use strict"; at the beginning of the file. As a statement, this does nothing and will be ignored by legacy JavaScript interpreters. Single function: using the mode for a complete file might break some functions in it, so by putting the line mentioned above at the beginning of a function, you can enable strict mode for it.
  10. It's not a main() MENTION APPLYMENTION APPLY MENTION APPLY
  11. https://javascript.info/garbage-collection There’s a base set of inherently reachable values, that cannot be deleted for obvious reasons. This algorithm looks out for objects which are unreachable from the root which is the JavaScript’s global object. This algorithm overcomes the limitations of Reference-counting algorithm. As an object with no references would be unreachable but not vice-versa.