JavaScript Boolean and dataView Complete Reference
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> // 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
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 |
Please Login to comment...