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
42
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
51
Web APIs 2019
orlando
0
82
Managing remote teams
orlando
0
51
How to be a Senior Software Engineer
orlando
0
99
Terraform Workshop
orlando
1
120
Infrastructure as Code with Terraform
orlando
0
260
Concurrencia, Paralelismo y el Event-loop
orlando
0
280
Talking Web Apps
orlando
0
52
Web Launchpad - Chelajs
orlando
0
160
Other Decks in Programming
See All in Programming
DDDはなぜ難しいのか / 良いコードの定義と設計能力の壁
pospome
25
7.6k
コミュニティに参加したことで起きた変化
ohmori_yusuke
3
130
Building a Smaller App Binary
kateinoigakukun
2
220
品質が高いコードって何?Rev2.1
ickx
1
490
TCAの Shared Stateって どういう仕組みになってんの?
yimajo
0
330
Material 3で Material 2ぽい見た目にする
numeroanddev
2
250
ONE WEDGE_Company_Information
1wedge
0
180
WebComponentsで フレームワークを1ページに共存させる
webuilder240
0
150
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
530
IntelliJ IDEA を知らなかった 自分に教えたい小ネタ集 / IntelliJ IDEA Hints for My Past Self
mackey0225
3
180
オブジェクト指向は必要なのか / Is object-oriented needed?
kishida
27
19k
チームでモデリングを育てるうえで 考えたこと・気づいたこと / Cultivating Modeling in Teams: Thoughts and Insights
mackey0225
5
2.4k
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
174
21k
Six Lessons from altMBA
skipperchong
19
2.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
11
1.4k
Bash Introduction
62gerente
604
210k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
225
51k
Agile that works and the tools we love
rasmusluckow
323
20k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Building Your Own Lightsaber
phodgson
97
5.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
15
6.3k
Into the Great Unknown - MozCon
thekraken
10
830
Fantastic passwords and where to find them - at NoRuKo
philnash
35
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
240
1.2M
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