Skip to content

Instantly share code, notes, and snippets.

typeof undefined // 'undefined'
typeof null // 'object'
({}).toString() // '[object Object]'
[].toString() // ''
({}).valueOf() // {}
[].valueOf() // []
@ferreiratiago
ferreiratiago / slice.js
Last active May 15, 2018 15:05
JS WTF
[1,2,3].slice(0, null) // []
[1,2,3].slice(0, undefined) // [1,2,3]
@BohdanLevchenko
BohdanLevchenko / SafeJson.java
Created October 11, 2017 18:33
Json helper for nullable properties
import javax.json.*;
/**
* Usage:
* class SomeClass {
* //...
* public JsonValue toJson() {
* return Json.createObjectBuilder().add("id", this.someId)
* .add("zipCode", SafeJson.nvl(this.someNullableInt))
* .add("phone", SafeJson.nvl(this.someNullableString))
> 0.1.toString(2)
'0.0001100110011001100110011001100110011001100110011001101'
> 0.2.toString(2)
'0.001100110011001100110011001100110011001100110011001101'