We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 91fd1d2 commit 2a828b3Copy full SHA for 2a828b3
part1 (Basics)/20_unary.js
@@ -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