Skip to content

Instantly share code, notes, and snippets.

@yannickglt
Created March 23, 2017 21:27
Show Gist options
  • Save yannickglt/e59f8949ab07cae8254d4259545be532 to your computer and use it in GitHub Desktop.
Save yannickglt/e59f8949ab07cae8254d4259545be532 to your computer and use it in GitHub Desktop.
Pure javascript addition vs Lo-Dash add method
// With "+" operator
1 + undefined
// NaN
undefined + undefined
// NaN
"1" + "2"
// "12"
1 + "2"
// "12"
1 + {}
// 1[object Object]
1 + [2, 3]
// "12, 3"
// With Lo-Dash
_.add(1, undefined)
// 1
_.add(undefined, undefined)
// 0
_.add("1", "2")
// 3
_.add(1, "2")
// 3
_.add(1, {})
// NaN
_.add(1, [2, 3])
// NaN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment