DONATE  
MENU
HTML
PHP
JAVASCRIPT
AJAX
MYSQL
JSON
CSS

JavaScript Tutorials

INTRODUCTION

» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls

CONDITIONAL TESTING

» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement

LOOPS

» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop

FUNCTIONS

» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions

ARRAYS

» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays

OBJECTS

» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword

AJAX

» Introduction to AJAX

JSON

» Introduction to JSON

JAVASCRIPT DATES

» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)

MATH OBJECT

» Math Object

» Math Methods

HTML / JS DOM

» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events

MISCELLANEOUS

» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript

JAVASCRIPT EXAMPLES

» JavaScript Calculator

.. » JavaScript » Introduction » Boolean Object
Share Tweet WhatsApp

Boolean Object

JavaScript booleans though primitive have an object that can help in manipulating them. Booleans can also be created directly from the object,
var bool = new Boolean(true);
Nevertheless, It is best to create booleans using the explicit method e.g var bool = false;. The boolean object have properties and methods that can be used in manipulating all JavaScript booleans whether created from the booleans' object or using the explicit method of creating booleans. In this page, we shall get familiarized with some of these properties and methods. Properties 1. prototype The prototype property allows you to modify and add new properties or methods to the prototype from which every boolean object is created. By doing this, you can define new properties and methods every created boolean object will have in a document or script. 2. constructor This property contains the function used in defining the prototype from which a boolean object is created. Since, the Boolean prototype was predefined i.e it was defined in JavaScript by default and not by you, there is a limit to what you can see. Methods 1. toSource() This method is greatly depreciated and may not be supported in your browser or may no longer be in use. It returns a string representing the source of a boolean object.
<script>
var bool = new Boolean(1);
alert(bool.toSource());
</script>

Copy PRACTICE IT

2. toString() The toString() method of the boolean object converts the value (true or false) of a boolean to a string.
<script>
var isLogged = false;
var str = isLogged.toString();
alert(typeof(str));
</script>

Copy PRACTICE IT

3. valueOf() The valueOf() method returns the primitive value of a boolean.
<script>
var bool = true;
alert(bool.valueOf());
</script>

Copy PRACTICE IT

Using the valueOf() method in your code is meaningless. It is used internally by JS and it is what is used so that whenever you use or output a boolean(an object), it returns the value of the boolean instead of [object Boolean]. SUMMARY
  1. Every boolean though a primitive datatype has an object that contains certain properties and methods.
  2. The prototype property allows you to modify and add new properties and methods to the prototype from which every boolean is created.
  3. The constructor property enables you to access the constructor function used in defining objects for booleans.
  4. There are also methods such as the toSource(), toString() and valueOf().
Take a short quiz on Boolean Object.
Ask a question or tell us if Boolean Object is easy or not.
cent?

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.





StackBeginner 2021 © Joseph Omamode