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
47
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
63
Web APIs 2019
orlando
0
96
Managing remote teams
orlando
0
55
How to be a Senior Software Engineer
orlando
0
120
Terraform Workshop
orlando
1
140
Infrastructure as Code with Terraform
orlando
0
260
Concurrencia, Paralelismo y el Event-loop
orlando
0
310
Talking Web Apps
orlando
0
66
Web Launchpad - Chelajs
orlando
0
180
Other Decks in Programming
See All in Programming
ウォンテッドリーにおけるモバイルアプリ開発 / iOSDC Japan 2024 Sponsor Session
kubode
0
230
Mergeable Libraryで 高速なアプリ起動を実現しよう!
giginet
PRO
1
1.9k
健康第一!MetricKitで始めるアプリの健康診断 / App Health Checkups Starting with MetricKit
nekowen
4
800
Go Code Generation at newmo / 2024-08-27 #newmo_layerx_go
genkey6
0
520
詳解UIWindow
natmark
3
2.1k
Hono・Prisma・AWSでGeoなAPI開発
nokonoko1203
5
610
Amazon Neptuneで始める初めてのグラフDB ー グラフDBを使う意味を考える ー
satoshi256kbyte
2
110
Meet BrowserEngineKit
swiftty
0
190
全力の跳躍を捉える計測アプリを作る
ogijun2018
0
1.1k
New Order in Cascade Sorting Order
mugi_uno
3
2.5k
数値を文字列に整形する際の落とし穴とその解決策(iOSDC2024 ルーキーズLT) / iOSDC Japan 2024 Formatting Floating-Point Numbers
glassfiber
0
250
私のEbitengineの第一歩
qt_luigi
0
420
Featured
See All Featured
Building Applications with DynamoDB
mza
89
5.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
46
48k
For a Future-Friendly Web
brad_frost
173
9.3k
The Art of Programming - Codeland 2020
erikaheidi
48
13k
GitHub's CSS Performance
jonrohan
1029
450k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
41
6.4k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
38
9.1k
Building a Scalable Design System with Sketch
lauravandoore
458
32k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
Ruby is Unlike a Banana
tanoku
96
10k
Scaling GitHub
holman
458
140k
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