๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

[Javascript] Double Exclamation Operator

๋ฐœํ–‰์ผ: Feb, 2025
์กฐํšŒ์ˆ˜: 1
๋‹จ์–ด์ˆ˜: 67

Table of Contents

1. Traditional Method

Declare a temporary variable, copy the value, and then swap.


let a = 10;
let b = 20;
const temp = a;
a = b;
b = temp;

2. Modern Method

By using arrays and destructuring assignment, swapping can be done in a single line.


[b, a] = [a, b];

3. Double Exclamation Mark (!!) in JavaScript

In JavaScript, the double exclamation mark (!!) operator is used to convert a value to a boolean.


const a = [1, 2, 3];
const is_a_truthy = !!a; // true

const b = null;
const is_b_truthy = !!b; // false

const c = 0;
const is_c_truthy = !!c; // false

const d = "0";
const is_d_truthy = !!d; // true

Tags: #JavaScript#Double Exclamation Mark#Boolean Conversion
JUNA BLOG VISITORS
Today
7
 (
updown
-7
)
Total
657
 (
updown
+7
)

ยฉ 2025 juniyunapapa@gmail.com.