ES6 BooleanThe ES6 Boolean objects can represent two values, either 'true' or 'false'. In JavaScript, the Boolean is used as a function to get the value of an object, a variable, conditions, expressions, and many more in terms of true and false. The object has the initial false value if the value parameter is omitted or 0, negative, false, null, NaN, undefined, or an empty ("") string. Syntax There are three methods and two properties of the Boolean object. Let us try to understand the properties and methods of the Boolean object. Boolean PropertiesThere are two properties of the Boolean object that are tabulated as follows:
Let us try to elaborate on the above Boolean properties. ES6 Boolean constructor() propertyThe JavaScript Boolean constructor() method is used to return the reference to the Boolean function that created the Boolean prototype. Syntax Return value Example Output example.constructor() is : function Boolean() { [native code] } ES6 Boolean prototype propertyIt is an inbuilt property in ES6, which is used for adding new properties and methods to any Boolean instance such as Number, String, Date, etc. It is a global property which is available with almost all objects. Syntax Return value
Example Output Yellow Boolean MethodsThe Boolean object contains three methods, which are tabulated as follows:
Let us try to elaborate on the above Boolean methods. Boolean.prototype.toSource() methodThis method returns a string that contains the source code of the Boolean object. It overrides the Object.prototype.toSource() method. Note: This method is not compatible with all browsers.Syntax Example You can run the above example in the Firefox browser because this method is not compatible with other browsers. Boolean.prototype.toString() methodIt returns a string of either true or false depends on the Boolean object value. Syntax Example Output true Boolean.prototype.valueOf() methodIt returns the primitive value of the Boolean object. Syntax Example Output true Next TopicES6 void Keyword |