Skip to content
Related Articles

Related Articles

JavaScript Boolean and dataView Complete Reference

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 21 Nov, 2022
Improve Article
Save Article

JavaScript Boolean: Boolean is a datatype that returns either true or false. In JavaScript, a boolean is used as a function to get the value of a variable, object, conditions, expressions, etc in terms of true or false.

Syntax:

Boolean(variable/expression) 
 

Example: If the operands are equal, the equal to operator == returns true.

Javascript




<script>
    console.log(15 == 15)
    console.log(15 == 11)
</script>


Output:

true
false

Constructor:

JavaScript Boolean Constructor 

Description 

JavaScript Boolean Prototype Constructor The Boolean prototype Constructor property is used to add a new property and methods to all Boolean instances.

Properties:

JavaScript Boolean Property

Description

JavaScript Boolean constructor Property In JavaScript, the boolean constructor property returns the constructor function for an object.

 

 

 

Methods:

JavaScript Boolean Methods 

Description 

JavaScript boolean.toString() Method The boolean.toString() method is used to return a string either “true” or “false” depending upon the value of the specified boolean object.
JavaScript boolean.valueOf() Method The boolean.valueOf() method is used to return a boolean value either “true” or “false” depending upon the value of the specified boolean object.

JavaScript dataView: The DataView function in JavaScript provides an interface to read and write more than one number type into an ArrayBuffer.

Syntax:

new DataView(buffer, byteOffset, byteLength)

Example: JavaScript code to show the working of dataView() function:

Javascript




<script>
   // Creating an ArrayBuffer with a size in bytes
   var buffer = new ArrayBuffer(16);
    
   // Creating views
   var view1 = new DataView(buffer);
       
   // Creating view from byte 0 for the next 4 bytes
   var view2 = new DataView(buffer,0,4); 
       
   // Creating view from byte 12 for the next 2 bytes
   var view3 = new DataView(buffer,12,2);
    
   // Putting 1 in slot 0
   view1.setInt8(0, 1); 
       
   // Putting 2 in slot 12
   view1.setInt8(12, 2)
    
   // Printing the views
   console.log(view2.getInt8(0))
   console.log(view3.getInt8(0))
</script>


Output:

1
2

Methods:

JavaScript dataview Methods 

Description

JavaScript dataView.getFloat32() Method The dataView.getFloat32() is an inbuilt function in dataView that is used to get a 32-bit float at the specified location.
JavaScript dataView.getFloat64() Method The dataView.getFloat64() is an inbuilt function in dataView that is used to get a 64-bit float at the specified location.
JavaScript  dataView.getInt8() Method The dataView.getInt8() is a method in dataView which is used to get an 8-bit integer in the byte at the specified location 
that from the start of the dataView.
JavaScript dataView.getInt16() Method The dataView.getInt16() is an inbuilt function in dataView that is used to get a 16-bit integer at the specified location.
JavaScript dataView.getInt32() Method The dataView.getInt32() is an inbuilt function in dataView that is used to get a 32-bit integer at the specified location.
JavaScript dataView.getUint8() Method The dataView.getUint8() is an inbuilt function in dataView that is used to get an unsigned 8-bit integer at the specified location.
JavaScript dataView.getUint16() Method The dataView.getUint16() is an inbuilt function in dataView that is used to get an unsigned 16-bit integer at the specified location.
JavaScript dataView.getUint32() Method The dataView.getUint32() is an inbuilt function in dataView that is used to get an unsigned 32-bit integer at the specified location.
JavaScript dataView.setFloat32() Method The dataView.setFloat32() is an inbuilt function in dataView that is used to store assigned 32-bit float value at the specified location.
JavaScript dataView.setFloat64() Method The dataView.setFloat64() is an inbuilt function in dataView that is used to store assigned 64-bit float value at the specified location.;
JavaScript dataView.setInt8() Method The dataView.setInt8() is an inbuilt function in dataView that is used to store a signed 8-bit integer at the specified location.
JavaScript dataView.setInt16() Method The dataView.setInt16() is an inbuilt function in dataView that is used to store assigned 16-bit integers at the specified location.
JavaScript dataView.setInt32() Method The dataView.setInt32() is an inbuilt function in dataView that is used to store assigned 32-bit integers at the specified location.
JavaScript dataView.setUint8() Method The dataView.setUint8() is an inbuilt function in dataView that is used to store an unsigned 8-bit integer at the specified location.
JavaScript dataView.setUint16() Method The dataView.setUint16() is an inbuilt function in dataView that is used to store an unsigned 16-bit integer at the specified location.
JavaScript dataView.setUint32() Method The dataView.setUint32() is an inbuilt function in dataView that is used to store an unsigned 32-bit integer at the specified location.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!