JavaScript Boolean and dataView Complete Reference
Last Updated :
10 Jan, 2023
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
|
Prototype |
Add a new property and methods to all Boolean instances |
JavaScript Boolean Methods
Methods
|
Description
|
toString() |
Return a string either “true” or “false” depending upon the value of the specified boolean object |
valueOf() |
Return a boolean value either “true” or “false” depending upon the value of the specified boolean object |
JavaScript Boolean Properties:
Property
|
Description
|
constructor |
Returns the constructor function for an object |
Methods:
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>
var buffer = new ArrayBuffer(16);
var view1 = new DataView(buffer);
var view2 = new DataView(buffer,0,4);
var view3 = new DataView(buffer,12,2);
view1.setInt8(0, 1);
view1.setInt8(12, 2)
console.log(view2.getInt8(0))
console.log(view3.getInt8(0))
</script>
|
Output:
1
2
JavaScript dataview Methods:
Methods
|
Description
|
getFloat32() |
Get a 32-bit float at the specified location |
getFloat64() |
Get a 64-bit float at the specified location |
getInt8() |
Get an 8-bit integer in the byte at the specified location |
getInt16() |
Get a 16-bit integer at the specified location |
getInt32() |
Get a 32-bit integer at the specified location |
getUint8() |
Get an unsigned 8-bit integer at the specified location |
getUint16() |
Get an unsigned 16-bit integer at the specified location |
getUint32() |
Get an unsigned 32-bit integer at the specified location |
setFloat32() |
Get an assigned 32-bit float value at the specified location |
setFloat64() |
Get an assigned 64-bit float value at the specified location; |
setInt8() |
Get an signed 8-bit integer at the specified location |
setInt16() |
Get an assigned 16-bit integers at the specified location |
setInt32() |
Get an assigned 32-bit integers at the specified location |
setUint8() |
Get an unsigned 8-bit integer at the specified location |
setUint16() |
Get an unsigned 16-bit integer at the specified location |
setUint32() |
Get an unsigned 32-bit integer at the specified location |
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...