2. JavaScript types, falsy, truthy, operators #7

Open
opened 2025-02-05 11:11:49 +01:00 by lang · 4 comments
Collaborator
No description provided.
lang changed title from JavaScript types, falsy, truthy, operators to 2. JavaScript types, falsy, truthy, operators 2025-02-05 11:20:46 +01:00
Owner

JavaScript 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)

JavaScript 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)
Owner

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.

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.
Owner

Ternary operator
condition ? ifTrue : if False

Conditional if else statement

Ternary operator condition ? ifTrue : if False Conditional if else statement
Owner

Data structures and types

The latest ECMAScript standard defines eight data types:
Seven data types that are primitives:

  1. Boolean - true or false
  2. null - A special keyword denoting a null value. JavaScript is case-sensitive, so it is not the same as NULL or Null.
  3. undefined - A top-level property whose value is not defined.
  4. Number - An integer or floating point number. For example 42 or 3,14159.
  5. BigInt - An integer with arbitrary precision. For example: 9007199254740992n.
  6. String - A sequence of characters that represent a text value. For example: "Howdy".
  7. Symbol - A data type whose instances are unique and immutable.

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.

**Data structures and types** The latest ECMAScript standard defines eight data types: Seven data types that are **primitives:** 1. Boolean - true or false 2. null - A special keyword denoting a null value. JavaScript is case-sensitive, so it is not the same as NULL or Null. 3. undefined - A top-level property whose value is not defined. 4. Number - An integer or floating point number. For example 42 or 3,14159. 5. BigInt - An integer with arbitrary precision. For example: 9007199254740992n. 6. String - A sequence of characters that represent a text value. For example: "Howdy". 7. Symbol - A data type whose instances are unique and immutable. 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.
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andi/Practice-1#7
No description provided.