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
43
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
55
Web APIs 2019
orlando
0
85
Managing remote teams
orlando
0
52
How to be a Senior Software Engineer
orlando
0
100
Terraform Workshop
orlando
1
120
Infrastructure as Code with Terraform
orlando
0
260
Concurrencia, Paralelismo y el Event-loop
orlando
0
290
Talking Web Apps
orlando
0
55
Web Launchpad - Chelajs
orlando
0
170
Other Decks in Programming
See All in Programming
CDKコントリビュートの最初の壁を越えよう! -簡単issueの見つけ方-
badmintoncryer
3
230
Deep Dive into React Stream/Serialize
mugi_uno
3
710
Balkan Ruby 2024 — How and why to run SQLite on Rails in production
fractaledmind
0
100
PHPはいつから死んでいるかの調査
chiroruxx
2
420
GraphQLサーバの構成要素を整理する #ハッカー鮨 #tsukijigraphql / graphql server technology selection
izumin5210
4
910
Sheets API使ってみた
toshi0383
2
170
GitLab CI/CD で C#/WPFアプリケーションのテストとインストーラーのビルド・デプロイを自動化する
hacarus
0
390
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
1
130
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
9
4.3k
SIMD Parallel Programming with the Vector API
josepaumard
0
230
パフォーマンスを求めてDBに機能を寄せる戦略
aoyagikouhei
0
110
2 週間で Twitter Bot を作ってみた
contour_gara
0
780
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Imperfection Machines: The Place of Print at Facebook
scottboms
261
12k
Building Effective Engineering Teams - LeadDev
addyosmani
32
1.9k
YesSQL, Process and Tooling at Scale
rocio
165
13k
A better future with KSS
kneath
231
16k
Side Projects
sachag
451
41k
Automating Front-end Workflow
addyosmani
1357
200k
Clear Off the Table
cherdarchuk
85
310k
Code Review Best Practice
trishagee
56
15k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
8
3.4k
Building Flexible Design Systems
yeseniaperezcruz
320
37k
Stop Working from a Prison Cell
hatefulcrawdad
267
19k
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