This time, we will output about Bool type
. Because, although I can explain the String type
and ʻInt type`, I couldn't verbalize the Bool type, so I will output it again here.
There is a concept of truth value
in the world of programming languages. The one that represents the truth value is Bool type
.
There are true
and false
literals that represent truth values, and when you assign a true
or false
to a variable, the Bool type
is assigned as an implicit type.
var sample = true //Bool type
Bool type is used for logical operation
. An operation is to perform some processing on the data and obtain the resulting value.
type | Contents | Operator to use |
---|---|---|
denial | Reverse the truth of the truth value | Prefix operator! |
Logical sum | True if either of the multiple truth values is true | Medium value operator || |
Logical AND | True if both of the multiple truth values are true | Neutral operator&& |
//denial
let sample1 = true //true (true)
let sample2 = !sample1 //false (false)
//Logical sum
sample1 || sample2 //true because sample1 is true
//Logical AND
sasmple1 && sample2 //sample1 is true, but sample2 is false, so false
Recommended Posts