SlideShare une entreprise Scribd logo
1  sur  33
JavaScript
1995, Brendan Eich, Netscape
ECMAScript
Usage
Browsers Server Desktop
 interpreted
JS Features:
runtime interpreters
Futhark, InScript, JScript, KJS, Linear B, QtScript, Rhino, YAJI, Duktape
just-in-time interpreters
~2008
Carakan, Chakra, SpiderMonkey, SquirrelFish, Tamarin, V8, JavaScriptCore, Nashorn
ie9 Chakra
google’s V8
no intermediate byte codes, no interpreter
property access
point.x
# ebx = the point object
cmp [ebx,<hidden class offset>],<cached hidden class>
jne <inline cache miss>
mov eax,[ebx, <cached x offset>]
 interpreted
 loose typed
JS Features:
Number String Boolean Object
Array Function Classes
Date
Regexp
Error
Null Undefined
variable types
variable declaration
naming rules:
 a-z, A-Z, _, $
 num6ers (4ever)
 case sensitive (type / Type)
 non-reserved words
ES5
ES6
variable declaration
naming rules:
 a-z, A-Z, _, $
 num6ers (4ever)
 case sensitive (type / Type)
 non-reserved words
var a;
var a = 5;
a = 5;
a;
ReferenceError: a is not defined
ways of declaration:
let a;
let a = 5;
 interpreted
 loose typed
 closures
JS Features:
closures
function parent(){
var width = 5;
var keyword = 'ages';
console.log(width);
console.log(keyword);
console.log(age);
child();
function child(){
var width = 20,
age = 5;
console.log(width);
console.log(keyword);
console.log(age);
}
console.log(age);
console.log(width);
}
5
ages
ReferenceError: age is not defined
20
ages
5
5
ReferenceError: age is not defined
closures
function parent(){
var width = 5;
var keyword = 'ages';
console.log(width);
console.log(keyword);
console.log(age);
if (true){
var width = 20,
age = 5;
console.log(width);
console.log(keyword);
console.log(age);
}
console.log(age);
console.log(width);
}
5
ages
ReferenceError: age is not defined
20
ages
5
5
5
closures
function parent(){
var width = 5;
var keyword = 'ages';
console.log(width);
console.log(keyword);
console.log(age);
if (true){
let width = 20,
age = 5;
console.log(width);
console.log(keyword);
console.log(age);
}
console.log(age);
console.log(width);
}
5
ages
ReferenceError: age is not defined
20
ages
5
20
ReferenceError: age is not defined
ES6
 interpreted
 loose typed
 closures
 multi-paradigmal
JS Features:
 imperative
 functional
 object-oriented
Arrays
var a = new Array();
a = [];
console.log(a.length);
var b = new Array(3,4,5,6);
b = [3,4,5,6];
console.log(b[2]);
a[3] = 'wat';
console.log(a.length);
console.log(a);
read & write
same}
same}
element accessing
element modifying
5
4
0
[undefined × 3, "wat"]
Arrays
modifying
var ar = [3,5];
adding el to array
adding several els to array
form string splitted with char
reversing order of els
adding new els to array
removing last element
[3,5, 10];
[3,5, 10, -5, 20, -2];
[3,5, 10, -5, 20];
3 + 5 + 10 + -5 + 20
[20, -5, 10, 5, 3];
[20, -5, 10, 5, 3, -3, -5];
ar.push(10);
ar.push(-5, 20, -2);
ar.pop();
var str = ar.join(' + ');
ar.reverse();
var secAr = [-3, -5];
ar = ar.concat(secAr);
assigning el to undefined [20, -5, 10, 5, undefined, -3, -5]delete ar[4]
Arrays
modifying
var ar = [3, 5, -10, 6, 20, -10];
returns ar from pos 1
returns 4 els from pos 2
adds els to the start
returns ar from pos 2 from the end
[5, -10, 6, 20, -10];
[-10, 6, 20, -10];
[20, -10];
[4, -5, 7, 5, ‘newbie’, ‘new one’, 20, -10];
ar.slice(1);
ar.slice(2,4);
ar.slice(-2);
ar.splice(2,1);
ar.splice(1,2, 'new one');
ar.splice(1,0, 'newbie');
ar.shift();
ar.unshift(5);
ar.unshift(4, -5, 7);
ar.unshift(); does nothing [4, -5, 7, 5, ‘newbie’, ‘new one’, 20, -10];
adds el to the start [5, ‘newbie’, ‘new one’, 20, -10];
removes el from the start [‘newbie’, ‘new one’, 20, -10];
removes el from pos 2
removes 2 els from pos 1, adds el
adds el to pos 1
[3, 5, 6, 20, -10];
[3, ‘new one’, 20, -10];
[3, ‘newbie’, ‘new one’, 20, -10];
Arrays
traversing
var ar = [-2, 4, 7];
Iterates through array 0 6 9
a should be earlier
for (var i = 0; i < ar.length; i++){
console.log(ar[i] + 2);
}
ar.sort(function(a, b){
if (a > b){
return -1;
} else if (a === 0) {
return 0;
} else {
return 1;
}
});
ar.sort(function(a, b){
return b - a;
});
do nothing
b should be earlier
same result
[7, 4, -2]
[7, 4, -2]
var ar = [10, 20, -5];
ar.forEach(function(el, idx, array){
console.log(el, idx);
});
ar.filter(function(el){
if (el > 0) return true;
});
ar.map(function(el){
return el * 2;
});
ar.reduce(function(a, b){
return a + b;
});
ar.reduceRight(function(a, b){
return a + 0.5 * b;
});
Arrays
traversing
Iterates through array 0 6 9
returns filtered array [10, 20]
performs action on every el [20, 40, -10]
forms one value by performing action to els from the left 25
forms one value by performing action to els from the right 10
ES5
Functions
 first-class
 are actually objects
 can represent constructors for OOP
 can be passed as a parameter
 can take context
 variadic
Functions
function countToNumber(first, last){
var countOnce = function (options){
return options.interim + options.number + options.divider;
}
var result = '';
if (arguments.length === 1) last = 10;
while (typeof first === 'number' && typeof last === 'number' && first <= last){
var params = {
number: first,
divider: '-',
interim: result
};
result = countOnce(params);
first++;
}
return result;
}
console.log(countToNumber(1, 5));
function declaration
function expression nested function
passing hash as an argument
variadic function use
1-2-3-4-5-
declaration & call
(function (str, callback){
if (typeof str === 'string'){
str = str.replace(/pain/g, 'fun');
callback(str);
}
})(str, logFirstWord);
var str = 'invoking function is pain';
function logFirstWord(param){
if (typeof param === 'string'){
var words = param.split(' ');
console.log(words[words.length - 1]);
} else {
throw new Error('Parameter is not a string');
}
}
Functions
immediately-invoked
passing function as an argument
calling function as a constructor
fun
Immediately-invoked
Classes
 absent
 we’ll still call them classes though they’re objects
 access modifiers are absent
 we can emulate them
 inheritance is prototype-based
 composition over inheritance from the box
Classes
function Programmer(options){
this.languages = ['python', 'js'];
this.yearsXP = 1;
this.learnLanguage = function(name){
if (typeof name === 'string'){
this.languages.push(name);
}
}
}
var stewie = new Programmer();
stewie.learnLanguage('ruby');
console.log(stewie.languages);
var hamid = new Programmer();
hamid.learnLanguage('c#');
console.log(hamid.languages);
function-constructor
this points to the object's context
defining method by passing function as a property
creating instance of a Programmer class
["python", "js", "ruby"]
["python", "js", “c#"]
creating / instantiating
Classesfunction Programmer(options){
var languages = ['python', 'js'];
this.yearsXP = 1;
this.learnLanguage = function(name){
if (typeof name === 'string'){
languages.push(name);
logNewLanguage(name);
}
}
function logNewLanguage(language){
console.log(language);
}
}
Programmer.prototype.gainXP = function(years){
if (typeof years === 'number'){
this.yearsXP += years;
}
}
var suzy = new Programmer();
suzy.learnLanguage('php');
suzy.logNewLanguage('php');
private property
private method
logs ‘php’
TypeError: Object #<Programmer> has no method 'logNewLanguage‘
defining method using prototype
using prototype
privileged method
Classes
emulating private members
Programmer = function (options){
var languages = ['python', 'js'];
this.yearsXP = 1;
this.projects = [];
this.projects['Academy'] = {
monthsEstimated: 2,
codeLinesEstimated: 10000
};
}
Programmer.prototype.justCode = function(projectName) {
if (typeof projectName !== 'undefined' && typeof this.projects[projectName] !== 'undefined')
var percents = 30;
var linesScaffolded = scaffold.call(this, projectName, percents);
var linesCoded = codeWithHands.apply(this, [projectName, linesScaffolded]);
console.log('scaffolded ' + linesScaffolded, ' coded ' + linesCoded);
};
function scaffold(projectName, percents){
if (this.projects[projectName].codeLinesEstimated > 0 && percents > 0 && percents < 100){
return Math.ceil(this.projects[projectName].codeLinesEstimated / 100) * percents;
}
}
function codeWithHands(projectName, linesScaffolded){
return this.projects[projectName].codeLinesEstimated - linesScaffolded;
}
var lee = new Programmer();
lee.justCode('Academy');
public method
private method
private method
parameters as usual
parameters within array
context passing}
logs ‘scaffolded 3000 coded 7000’
Classes
inheritance
function Man(){
this.inheritedProperty = 5;
}
Man.prototype.setName = function(name) {
if (typeof name === 'string'){
this.name = name;
}
};
Man.prototype.introduce = function() {
console.log("Hi, my name is " + this.name);
};
var kelly = new Man();
kelly.setName('Kelly');
kelly.introduce();
function Programmer(){
this.selfProperty = 5;
}
Programmer.prototype = new Man();
var joe = new Programmer();
joe.setName('Joe');
joe.introduce();
constructor
constructor
inheriting prototype members of super
Hi, my name is Kelly
Hi, my name is Joe
Programmer
name: "Joe"
selfProperty: 5
__proto__: Man
inheritedProperty: 5
__proto__: Man
constructor: function Man(){
introduce: function () {
setName: function (name) {
__proto__: Object
__defineGetter__: function
__defineSetter__: function
....
Thanks
https://github.com/msemenistyi/js-basics/
@msemenistyi
nikita.s_binary
nikita.semenistyi@binary-studio.com

Contenu connexe

Tendances

Tendances (20)

JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Java script
Java scriptJava script
Java script
 
Xml http request
Xml http requestXml http request
Xml http request
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
JavaScript Inheritance
JavaScript InheritanceJavaScript Inheritance
JavaScript Inheritance
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operators
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Operators in java
Operators in javaOperators in java
Operators in java
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
JavaScript Control Statements II
JavaScript Control Statements IIJavaScript Control Statements II
JavaScript Control Statements II
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 

En vedette

11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile Applications11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile ApplicationsAEGIS-ACCESSIBLE Projects
 
Java ME - 02 - High Level UI
Java ME - 02 - High Level UIJava ME - 02 - High Level UI
Java ME - 02 - High Level UIAndreas Jakl
 
Java in the Air: A Case Study for Java-based Environment Monitoring Stations
Java in the Air: A Case Study for Java-based Environment Monitoring StationsJava in the Air: A Case Study for Java-based Environment Monitoring Stations
Java in the Air: A Case Study for Java-based Environment Monitoring StationsEurotech
 
Statistical Process Control Tools
Statistical Process Control ToolsStatistical Process Control Tools
Statistical Process Control ToolsRaja Farhan Saeed
 
AggreGate SCADA/HMI
AggreGate SCADA/HMI AggreGate SCADA/HMI
AggreGate SCADA/HMI Tibbo
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_scriptVijay Kalyan
 

En vedette (8)

11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile Applications11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile Applications
 
Java ME - 02 - High Level UI
Java ME - 02 - High Level UIJava ME - 02 - High Level UI
Java ME - 02 - High Level UI
 
J2ME GUI Programming
J2ME GUI ProgrammingJ2ME GUI Programming
J2ME GUI Programming
 
Java in the Air: A Case Study for Java-based Environment Monitoring Stations
Java in the Air: A Case Study for Java-based Environment Monitoring StationsJava in the Air: A Case Study for Java-based Environment Monitoring Stations
Java in the Air: A Case Study for Java-based Environment Monitoring Stations
 
Statistical Process Control Tools
Statistical Process Control ToolsStatistical Process Control Tools
Statistical Process Control Tools
 
AggreGate SCADA/HMI
AggreGate SCADA/HMI AggreGate SCADA/HMI
AggreGate SCADA/HMI
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
Java script
Java scriptJava script
Java script
 

Similaire à Javascript Basics

FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Transducers in JavaScript
Transducers in JavaScriptTransducers in JavaScript
Transducers in JavaScriptPavel Forkert
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMDdhaval10690
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersRick Beerendonk
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей КоваленкоFwdays
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyondFrancis Johny
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetJose Perez
 

Similaire à Javascript Basics (20)

Javascript
JavascriptJavascript
Javascript
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Transducers in JavaScript
Transducers in JavaScriptTransducers in JavaScript
Transducers in JavaScript
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMD
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
8558537werr.pptx
8558537werr.pptx8558537werr.pptx
8558537werr.pptx
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
 

Dernier

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 

Dernier (20)

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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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?
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 

Javascript Basics

  • 2. 1995, Brendan Eich, Netscape ECMAScript
  • 3.
  • 6. runtime interpreters Futhark, InScript, JScript, KJS, Linear B, QtScript, Rhino, YAJI, Duktape just-in-time interpreters ~2008 Carakan, Chakra, SpiderMonkey, SquirrelFish, Tamarin, V8, JavaScriptCore, Nashorn
  • 8. google’s V8 no intermediate byte codes, no interpreter property access point.x # ebx = the point object cmp [ebx,<hidden class offset>],<cached hidden class> jne <inline cache miss> mov eax,[ebx, <cached x offset>]
  • 9.  interpreted  loose typed JS Features:
  • 10. Number String Boolean Object Array Function Classes Date Regexp Error Null Undefined variable types
  • 11. variable declaration naming rules:  a-z, A-Z, _, $  num6ers (4ever)  case sensitive (type / Type)  non-reserved words
  • 12. ES5
  • 13. ES6
  • 14. variable declaration naming rules:  a-z, A-Z, _, $  num6ers (4ever)  case sensitive (type / Type)  non-reserved words var a; var a = 5; a = 5; a; ReferenceError: a is not defined ways of declaration: let a; let a = 5;
  • 15.  interpreted  loose typed  closures JS Features:
  • 16. closures function parent(){ var width = 5; var keyword = 'ages'; console.log(width); console.log(keyword); console.log(age); child(); function child(){ var width = 20, age = 5; console.log(width); console.log(keyword); console.log(age); } console.log(age); console.log(width); } 5 ages ReferenceError: age is not defined 20 ages 5 5 ReferenceError: age is not defined
  • 17. closures function parent(){ var width = 5; var keyword = 'ages'; console.log(width); console.log(keyword); console.log(age); if (true){ var width = 20, age = 5; console.log(width); console.log(keyword); console.log(age); } console.log(age); console.log(width); } 5 ages ReferenceError: age is not defined 20 ages 5 5 5
  • 18. closures function parent(){ var width = 5; var keyword = 'ages'; console.log(width); console.log(keyword); console.log(age); if (true){ let width = 20, age = 5; console.log(width); console.log(keyword); console.log(age); } console.log(age); console.log(width); } 5 ages ReferenceError: age is not defined 20 ages 5 20 ReferenceError: age is not defined ES6
  • 19.  interpreted  loose typed  closures  multi-paradigmal JS Features:  imperative  functional  object-oriented
  • 20. Arrays var a = new Array(); a = []; console.log(a.length); var b = new Array(3,4,5,6); b = [3,4,5,6]; console.log(b[2]); a[3] = 'wat'; console.log(a.length); console.log(a); read & write same} same} element accessing element modifying 5 4 0 [undefined × 3, "wat"]
  • 21. Arrays modifying var ar = [3,5]; adding el to array adding several els to array form string splitted with char reversing order of els adding new els to array removing last element [3,5, 10]; [3,5, 10, -5, 20, -2]; [3,5, 10, -5, 20]; 3 + 5 + 10 + -5 + 20 [20, -5, 10, 5, 3]; [20, -5, 10, 5, 3, -3, -5]; ar.push(10); ar.push(-5, 20, -2); ar.pop(); var str = ar.join(' + '); ar.reverse(); var secAr = [-3, -5]; ar = ar.concat(secAr); assigning el to undefined [20, -5, 10, 5, undefined, -3, -5]delete ar[4]
  • 22. Arrays modifying var ar = [3, 5, -10, 6, 20, -10]; returns ar from pos 1 returns 4 els from pos 2 adds els to the start returns ar from pos 2 from the end [5, -10, 6, 20, -10]; [-10, 6, 20, -10]; [20, -10]; [4, -5, 7, 5, ‘newbie’, ‘new one’, 20, -10]; ar.slice(1); ar.slice(2,4); ar.slice(-2); ar.splice(2,1); ar.splice(1,2, 'new one'); ar.splice(1,0, 'newbie'); ar.shift(); ar.unshift(5); ar.unshift(4, -5, 7); ar.unshift(); does nothing [4, -5, 7, 5, ‘newbie’, ‘new one’, 20, -10]; adds el to the start [5, ‘newbie’, ‘new one’, 20, -10]; removes el from the start [‘newbie’, ‘new one’, 20, -10]; removes el from pos 2 removes 2 els from pos 1, adds el adds el to pos 1 [3, 5, 6, 20, -10]; [3, ‘new one’, 20, -10]; [3, ‘newbie’, ‘new one’, 20, -10];
  • 23. Arrays traversing var ar = [-2, 4, 7]; Iterates through array 0 6 9 a should be earlier for (var i = 0; i < ar.length; i++){ console.log(ar[i] + 2); } ar.sort(function(a, b){ if (a > b){ return -1; } else if (a === 0) { return 0; } else { return 1; } }); ar.sort(function(a, b){ return b - a; }); do nothing b should be earlier same result [7, 4, -2] [7, 4, -2]
  • 24. var ar = [10, 20, -5]; ar.forEach(function(el, idx, array){ console.log(el, idx); }); ar.filter(function(el){ if (el > 0) return true; }); ar.map(function(el){ return el * 2; }); ar.reduce(function(a, b){ return a + b; }); ar.reduceRight(function(a, b){ return a + 0.5 * b; }); Arrays traversing Iterates through array 0 6 9 returns filtered array [10, 20] performs action on every el [20, 40, -10] forms one value by performing action to els from the left 25 forms one value by performing action to els from the right 10 ES5
  • 25. Functions  first-class  are actually objects  can represent constructors for OOP  can be passed as a parameter  can take context  variadic
  • 26. Functions function countToNumber(first, last){ var countOnce = function (options){ return options.interim + options.number + options.divider; } var result = ''; if (arguments.length === 1) last = 10; while (typeof first === 'number' && typeof last === 'number' && first <= last){ var params = { number: first, divider: '-', interim: result }; result = countOnce(params); first++; } return result; } console.log(countToNumber(1, 5)); function declaration function expression nested function passing hash as an argument variadic function use 1-2-3-4-5- declaration & call
  • 27. (function (str, callback){ if (typeof str === 'string'){ str = str.replace(/pain/g, 'fun'); callback(str); } })(str, logFirstWord); var str = 'invoking function is pain'; function logFirstWord(param){ if (typeof param === 'string'){ var words = param.split(' '); console.log(words[words.length - 1]); } else { throw new Error('Parameter is not a string'); } } Functions immediately-invoked passing function as an argument calling function as a constructor fun Immediately-invoked
  • 28. Classes  absent  we’ll still call them classes though they’re objects  access modifiers are absent  we can emulate them  inheritance is prototype-based  composition over inheritance from the box
  • 29. Classes function Programmer(options){ this.languages = ['python', 'js']; this.yearsXP = 1; this.learnLanguage = function(name){ if (typeof name === 'string'){ this.languages.push(name); } } } var stewie = new Programmer(); stewie.learnLanguage('ruby'); console.log(stewie.languages); var hamid = new Programmer(); hamid.learnLanguage('c#'); console.log(hamid.languages); function-constructor this points to the object's context defining method by passing function as a property creating instance of a Programmer class ["python", "js", "ruby"] ["python", "js", “c#"] creating / instantiating
  • 30. Classesfunction Programmer(options){ var languages = ['python', 'js']; this.yearsXP = 1; this.learnLanguage = function(name){ if (typeof name === 'string'){ languages.push(name); logNewLanguage(name); } } function logNewLanguage(language){ console.log(language); } } Programmer.prototype.gainXP = function(years){ if (typeof years === 'number'){ this.yearsXP += years; } } var suzy = new Programmer(); suzy.learnLanguage('php'); suzy.logNewLanguage('php'); private property private method logs ‘php’ TypeError: Object #<Programmer> has no method 'logNewLanguage‘ defining method using prototype using prototype privileged method
  • 31. Classes emulating private members Programmer = function (options){ var languages = ['python', 'js']; this.yearsXP = 1; this.projects = []; this.projects['Academy'] = { monthsEstimated: 2, codeLinesEstimated: 10000 }; } Programmer.prototype.justCode = function(projectName) { if (typeof projectName !== 'undefined' && typeof this.projects[projectName] !== 'undefined') var percents = 30; var linesScaffolded = scaffold.call(this, projectName, percents); var linesCoded = codeWithHands.apply(this, [projectName, linesScaffolded]); console.log('scaffolded ' + linesScaffolded, ' coded ' + linesCoded); }; function scaffold(projectName, percents){ if (this.projects[projectName].codeLinesEstimated > 0 && percents > 0 && percents < 100){ return Math.ceil(this.projects[projectName].codeLinesEstimated / 100) * percents; } } function codeWithHands(projectName, linesScaffolded){ return this.projects[projectName].codeLinesEstimated - linesScaffolded; } var lee = new Programmer(); lee.justCode('Academy'); public method private method private method parameters as usual parameters within array context passing} logs ‘scaffolded 3000 coded 7000’
  • 32. Classes inheritance function Man(){ this.inheritedProperty = 5; } Man.prototype.setName = function(name) { if (typeof name === 'string'){ this.name = name; } }; Man.prototype.introduce = function() { console.log("Hi, my name is " + this.name); }; var kelly = new Man(); kelly.setName('Kelly'); kelly.introduce(); function Programmer(){ this.selfProperty = 5; } Programmer.prototype = new Man(); var joe = new Programmer(); joe.setName('Joe'); joe.introduce(); constructor constructor inheriting prototype members of super Hi, my name is Kelly Hi, my name is Joe Programmer name: "Joe" selfProperty: 5 __proto__: Man inheritedProperty: 5 __proto__: Man constructor: function Man(){ introduce: function () { setName: function (name) { __proto__: Object __defineGetter__: function __defineSetter__: function ....