---
title: "느낌표 두 개 연산자"
date: "2022-03-19"
tags: ["TIL","JS"]
status: archived
verified: false
---

## 느낌표 두개 (Double Exclamation Marks) 연산자

-   nonboolean형 타입을 boolean 형으로 바꾸기 위해 사용
-   사실 연산자(Operator)는 아니고 단지 두 번의 부정을 수행하는 것

```js
// 아래와 두 결과는 같음
Boolean(5) === !!5;

!!false === false;
!!true === true;

!!0 === false;
!!parseInt("foo") === false; // NaN is falsey
!!1 === true;
!!-1 === true; // -1 is truthy
!!(1 / 0) === true; // Infinity is truthy

!!"" === false; // empty string is falsey
!!"foo" === true; // non-empty string is truthy
!!"false" === true; // ...even if it contains a falsey value

!!window.foo === false; // undefined value is falsey
!!undefined === false; // undefined primitive is falsey
!!null === false; // null is falsey

!!{} === true; // an (empty) object is truthy
!![] === true; // an (empty) array is truthy;

!!new Boolean(false); // 객체니까 truthy 때문에 true
!!Boolean(false); // false
```

### 참고

-   [stackoverflow - What is the !!(not not) operator in JavaScript?](https://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript)
