JavaScript Booleans
JavaScript 부울값(Boolean)은 두 가지지 중 하나를 취한다: true or false.
Boolean Values
프로그래밍에서 아주 자주 다음과 같은 두 값 중에서 하나만을 가질 필요가 있는 데이타 형식이 필요하게 된다.
- YES / NO
- ON / OFF
- TRUE / FALSE
이를 위해서 JavaScript 는 부울(Boolean) 데이타 형식을 사용한다. 이는 true or false 값 만을 가질 수 있다.
Boolean() Function
Boolean() 함수를 식(또는 변수)이 true 인지를 판단하는데 사용할 수 있다:
Or even easier:
비교(Comparisons) 와 조건(Conditions)
Here are some examples:Operator | Description | Example |
---|---|---|
== | equal to | if (day == "Monday") |
> | greater than | if (salary > 9000) |
< | less than | if (age < 18) |
식의 부울값(Boolean value)은 JavaScript 비교와 조건에 기본이 된다. |
Everything With a "Real" Value is True
Everything Without a "Real" is False
The Boolean value of -0
(minus zero) is false:
var x = -0;
Boolean(x); //
returns false
Try it Yourself » The Boolean value of "" (empty
string) is false:
var x = "";
Boolean(x); //
returns false
Try it Yourself » The Boolean value of false
is (you guessed it) false:
var x = false;
Boolean(x); //
returns false
Try it Yourself » Complete Boolean Reference
For a complete reference, go to our Complete JavaScript Boolean Reference.
The reference contains descriptions and examples of all Boolean properties and methods.