Skip to content

Commit 2a828b3

Browse files
feat: add unary operators
1 parent 91fd1d2 commit 2a828b3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

part1 (Basics)/20_unary.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Unary Operators in JavaScript
2+
3+
/*
4+
+ Unary plus (converts operand to number)
5+
- Unary minus (negates the operand)
6+
! Logical NOT (inverts boolean)
7+
delete Deletes a property from an object
8+
void Evaluates an expression and returns undefined
9+
*/
10+
11+
// Unary plus
12+
console.log(+'5'); // Output: 5 (string '5' converted to number)
13+
14+
// Unary minus
15+
console.log(-5); // Output: -5
16+
17+
// Logical NOT
18+
console.log(!true); // Output: false
19+
20+
// delete
21+
const obj = {a: 1, b: 2};
22+
delete obj.a;
23+
console.log(obj); // Output: { b: 2 }
24+
25+
// void
26+
console.log(void(0)); // Output: undefined

0 commit comments

Comments
 (0)