2. JavaScript types, falsy, truthy, operators #7
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
JavaScript types, falsy, truthy, operatorsto 2. JavaScript types, falsy, truthy, operatorsJavaScript has a set of values that can evaluate to true or false but may not equal true or false. Because of this we call these values truthy and falsy.
Falsy: All falsy values will be false in a boolean context.
const falsy = [
false,
0,
-0,
"", (empty string)
null,
undefined,
Nan,
0n, (BigInt)
];
(evaluate to false)
Truthy (everything else - that is not falsy- is truthy)
const truthy = [
true,
non-zero numbers,
"strings"
objects,
arrays,
functions
]
(evaluate to true)
Undefined means that a variable doesn't exist and the interpreter doesn't know what you are referring to.
Null means that the variable exist, but has no value. It is usually used as a placeholder.
Nan means it is not a number or a result that is not a number.
Ternary operator
condition ? ifTrue : if False
Conditional if else statement
Data structures and types
The latest ECMAScript standard defines eight data types:
Seven data types that are primitives:
and Object
Although these data types are relatively few, they enable you to perform useful operations with your applications. Functions are the other fundamental elements of the language. While functions are technically a kind of object, you can think of objects as named containers for values, and functions as procedures that your script can perform.