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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Orlando Del Aguila
March 13, 2015
Programming
82
1
Share
JavaScript Type Conversions
JavaScript Type Conversions and some explanations to the Gary Bernhardt's wat lighting talk
Orlando Del Aguila
March 13, 2015
More Decks by Orlando Del Aguila
See All by Orlando Del Aguila
Open Source + Nonprofits = 💪
orlando
0
110
Web APIs 2019
orlando
0
170
Managing remote teams
orlando
0
86
How to be a Senior Software Engineer
orlando
0
160
Terraform Workshop
orlando
1
180
Infrastructure as Code with Terraform
orlando
0
330
Concurrencia, Paralelismo y el Event-loop
orlando
0
400
Talking Web Apps
orlando
0
130
Web Launchpad - Chelajs
orlando
0
260
Other Decks in Programming
See All in Programming
SPMマルチモジュールで テストカバレッジを取得する技法
yosshi4486
0
130
Moments When Things Go Wrong
aurimas
3
130
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
480
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
230
Oxlintのカスタムルールの現況
syumai
5
910
誰も頼んでない機能を出荷した話
zekutax
0
150
Inside Stream API
skrb
1
430
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
1.8k
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
390
ふつうのFeature Flag実践入門
irof
7
3.4k
net-httpのHTTP/2対応について
naruse
0
380
今さら聞けないCancellationToken
htkym
0
210
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.5k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
390
A designer walks into a library…
pauljervisheath
211
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.3k
Git: the NoSQL Database
bkeepers
PRO
432
67k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
370
Rails Girls Zürich Keynote
gr2m
96
14k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
520
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