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
65
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
88
Web APIs 2019
orlando
0
140
Managing remote teams
orlando
0
70
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
100
Web Launchpad - Chelajs
orlando
0
220
Other Decks in Programming
See All in Programming
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
1k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
420
Software Architecture
hschwentner
6
2.4k
Go言語はstack overflowの夢を見るか?
logica0419
0
660
Swift Concurrency 年表クイズ
omochi
3
210
Developer Joy - The New Paradigm
hollycummins
1
380
SODA - FACT BOOK(JP)
sodainc
1
9k
Node-REDのノードの開発・活用事例とコミュニティとの関わり(Node-RED Con Nagoya 2025)
404background
0
110
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
300
モテるデスク環境
mozumasu
3
1.4k
Using Types to Save Your Code's Future
rollbear
0
100
AIと人間の共創開発!OSSで試行錯誤した開発スタイル
mae616
2
840
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
The World Runs on Bad Software
bkeepers
PRO
72
11k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
658
61k
A Tale of Four Properties
chriscoyier
161
23k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
2.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
For a Future-Friendly Web
brad_frost
180
10k
Done Done
chrislema
186
16k
Optimizing for Happiness
mojombo
379
70k
Code Review Best Practice
trishagee
72
19k
How STYLIGHT went responsive
nonsquared
100
5.9k
GitHub's CSS Performance
jonrohan
1032
470k
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