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
66
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
90
Web APIs 2019
orlando
0
140
Managing remote teams
orlando
0
71
How to be a Senior Software Engineer
orlando
0
150
Terraform Workshop
orlando
1
160
Infrastructure as Code with Terraform
orlando
0
290
Concurrencia, Paralelismo y el Event-loop
orlando
0
360
Talking Web Apps
orlando
0
110
Web Launchpad - Chelajs
orlando
0
220
Other Decks in Programming
See All in Programming
connect-python: convenient protobuf RPC for Python
anuraaga
0
230
Building AI with AI
inesmontani
PRO
1
260
詳細の決定を遅らせつつ実装を早くする
shimabox
2
1.3k
予防に勝る防御なし(2025年版) - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHP Conference Fukuoka 2025
twada
PRO
39
13k
Atomics APIを知る / Understanding Atomics API
ssssota
1
200
生成AIを活用したリファクタリング実践 ~コードスメルをなくすためのアプローチ
raedion
0
120
モデル駆動設計をやってみよう Modeling Forum2025ワークショップ/Let’s Try Model-Driven Design
haru860
0
180
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
0
490
知られているようで知られていない JavaScriptの仕様 4選
syumai
0
630
2025 컴포즈 마법사
jisungbin
0
150
「文字列→日付」の落とし穴 〜Ruby Date.parseの意外な挙動〜
sg4k0
0
270
レイトレZ世代に捧ぐ、今からレイトレを始めるための小径
ichi_raven
0
460
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.1k
Building Applications with DynamoDB
mza
96
6.8k
How to train your dragon (web standard)
notwaldorf
97
6.4k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8k
Building an army of robots
kneath
306
46k
KATA
mclloyd
PRO
32
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Making Projects Easy
brettharned
120
6.5k
The Invisible Side of Design
smashingmag
302
51k
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