[Javascript] Double Exclamation Operator

발행일: Feb, 2025
조회수: 0
단어수: 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

태그#JavaScript#Double Exclamation Mark#Boolean Conversion

JUNA BLOG VISITORS

오늘0
Total0