TIL Double Exclamation shorthand for booleans
POSTED ON:
TAGS: javascript booleans
Javascript follows Truthy/Falsy values.
If you're not familiar with it:
(Via Wes Bos)
But if you want to make it explicit:
JavaScript (and TypeScript) lets you convert a non-Boolean value to Boolean using the double exclamation shorthand.
const emptyStr = ''
const nonEmptyStr = 'test'
const emptyStrBool = !!emptyStr //false
const nonEmptyStrBool = !!nonEmptyStr //true
via Understanding the exclamation mark in TypeScript
Related TILs
Tagged: javascript