Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
JavaScript Type Conversions
Search
Orlando Del Aguila
March 13, 2015
Programming
1
60
JavaScript Type Conversions
JavaScript Type Conversions and some explanations to the Gary Bernhardt's wat lighting talk
Orlando Del Aguila
March 13, 2015
Tweet
Share
More Decks by Orlando Del Aguila
See All by Orlando Del Aguila
Open Source + Nonprofits = 💪
orlando
0
74
Web APIs 2019
orlando
0
120
Managing remote teams
orlando
0
60
How to be a Senior Software Engineer
orlando
0
140
Terraform Workshop
orlando
1
150
Infrastructure as Code with Terraform
orlando
0
280
Concurrencia, Paralelismo y el Event-loop
orlando
0
340
Talking Web Apps
orlando
0
89
Web Launchpad - Chelajs
orlando
0
200
Other Decks in Programming
See All in Programming
RubyKaigiで得られる10の価値 〜Ruby話を聞くことだけが RubyKaigiじゃない〜
tomohiko9090
0
100
型付け力を強化するための Hoogle のすゝめ / Boosting Your Type Mastery with Hoogle
guvalif
1
230
primeNumberでのRBS導入の現在 && RBS::Traceでinline RBSを拡充してみた
mnmandahalf
0
250
從零到一:搭建你的第一個 Observability 平台
blueswen
0
220
がんばりすぎないコーディングルール運用術
tsukakei
1
180
Interface vs Types ~型推論が過多推論~
hirokiomote
1
230
Cloudflare Realtime と Workers でつくるサーバーレス WebRTC
nekoya3
0
240
インターフェース設計のコツとツボ
togishima
2
490
Parallel::Pipesの紹介
skaji
2
870
Blueskyのプラグインを作ってみた
hakkadaikon
1
290
イベントストーミングから始めるドメイン駆動設計
jgeem
3
410
Spring gRPC で始める gRPC 入門 / Introduction to gRPC with Spring gRPC
mackey0225
0
140
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
512
110k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
106
19k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.8k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.3k
Product Roadmaps are Hard
iamctodd
PRO
53
11k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
Speed Design
sergeychernyshev
30
970
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
KATA
mclloyd
29
14k
BBQ
matthewcrist
88
9.7k
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
Transcript
JavaScript Type Conversions
JavaScript Primitives yes, js has primitives
1. undefined 2. null 3. number 4. string 5. boolean
1. undefined 2. null yep, is not an object 3.
number 4. string 5. boolean
JavaScript Binary Operators we are going to address only -
and +
On doubt check the spec
http://www.ecma-international.org/ecma-262/5.1/#sec-11.6.1 http://www.ecma-international.org/ecma-262/5.1/#sec-11.6.2
+ Operator
If lprim or rprim are strings, then concatenate lprim and
rprim and return the result
- Operator
ToNumber(lprim) - ToNumber(rprim)
Examples
var a, b; a = "bla"; b = "ble"; a
+ b; //=> "blable" a - b; //=> "NaN" a = "5"; b = "4"; a + b; //=> "54" a - b; //=> 1
var obj = { valueOf: function valueOf() { console.log("valueOf"); return
{}; // not a primitive }, toString: function toString() { console.log("toString"); return {}; // not a primitive } }; obj - 1; // valueOf // toString // error obj + 1; // valueOf // toString // error
var func = function () { console.log('exec'); return { valueOf:
function valueOf() { console.log("valueOf"); return {}; // not a primitive }, toString: function toString() { console.log("toString"); return {}; // not a primitive } }; }; func() + 1; // exec // valueOf // toString // error
{} + [] //=> +[] == 0 [] + {}
//=> '' + '[object Object]' == '[object Object]' [] - {} //=> 0 - NaN == NaN {} - [] //=> -[] == -0
None
WAT https://www.destroyallsoftware.com/talks/wat