JavaScript - o objeto booleano
o Booleanobjeto representa dois valores, "verdadeiro" ou "falso". Se o parâmetro de valor for omitido ou for 0, -0, nulo, falso,NaN, undefined, ou a string vazia (""), o objeto tem um valor inicial false.
Sintaxe
Use a seguinte sintaxe para criar um boolean objeto.
var val = new Boolean(value);
Propriedades Booleanas
Aqui está uma lista das propriedades do objeto Boolean -
Sr. Não. | Descrição da Propriedade |
---|---|
1 | constructor Returns a reference to the Boolean function that created the object. |
2 | prototype The prototype property allows you to add properties and methods to an object. |
In the following sections, we will have a few examples to illustrate the properties of Boolean object.
Boolean Methods
Here is a list of the methods of Boolean object and their description.
Sr.No. | Method & Description |
---|---|
1 | toSource() Returns a string containing the source of the Boolean object; you can use this string to create an equivalent object. |
2 | toString() Returns a string of either "true" or "false" depending upon the value of the object. |
3 | valueOf() Returns the primitive value of the Boolean object. |
In the following sections, we will have a few examples to demonstrate the usage of the Boolean methods.