DEV Community

Syed Muhammad Ali Raza
Syed Muhammad Ali Raza

Posted on

Javascript with Atomic,BigUint64Array, Boolean, DataView, decodeURI(), encodeURI()

Introduction

As a versatile and widely used programming language, JavaScript offers many features and functions. In this article, we will explore a set of basic JavaScript elements that every student should know.

These include Atomic, BigInt, BigInt64Array, BigUint64Array, Boolean, DataView, Date, decodeURI(), decodeURIComponent(), encodeURI(), encodeURIComponent(), error, escape() (default), value(), EvalError, FinalizationRegistry, and Floating64Array. We will explore each concept with simple examples to help you understand the basic application.

1. Atomics

Atomics objects provide atomic operations as static methods for shared memory and web workers. It is commonly used in multi-threaded JavaScript applications to ensure thread safety. Here is a basic example using Atomics:

const sharedArray = new Int32Array(new SharedArrayBuffer(4));

// Atomically update the shared array
Atomics.store(sharedArray, 0, 42);
console.log (Atomics.load (sharedArray, 0)); // 42
Enter fullscreen mode Exit fullscreen mode

2. BigInt

"BigInt" is an internal object that provides arbitrary precision numbers. Lets you work with numbers outside the scope of standard JavaScript numbers.

const bigIntNum = 1234567890123456789012345678901234567890n;
console.log(bigIntNum); // 1234567890123456789012345678901234567890n
Enter fullscreen mode Exit fullscreen mode

3. BigInt64Array and BigUint64Array

These typed Array objects allow working with signed and 64-bit integers, respectively.

const int64Array = new BigInt64Array([BigInt(42), BigInt(84)]);
console.log(int64Array[0]); // 42n

const uint64Array = new BigUint64Array([BigInt(42), BigInt(84)]);
console.log(uint64Array [1]); // 84n
Enter fullscreen mode Exit fullscreen mode

4. Boolean

A Boolean object represents a value. It is often used to change the shape or create an object.

const boolValue = new Boolean(false);
console.log(boolValue.valueOf()); // false
Enter fullscreen mode Exit fullscreen mode

5. DataView

DataView is used to read and write raw binary data to the buffer.

const buffer = new ArrayBuffer(4);
const view = new DataView(buffer);
view.setInt32(0, 42);
console.log(view.getInt32(0)); // 42
Enter fullscreen mode Exit fullscreen mode

6. Date

Date objects represent dates and times. It is widely used to work with dates and run date calculations.

const today = new Date();
console.log(today.toDateString()); // eg "September 13, 2023"
Enter fullscreen mode Exit fullscreen mode

7. decodeURI() and decodeURIComponent()

This function encodes URI or URI component encoded using "encodeURI()" or "encodeURIComponent()".

const encodedURI = "https%3A%2F%2Fwww.example.com%2F";
const decodeURI = decodeURI( decodeURI );
console.log (decoded); // "https://www.example.com/"
Enter fullscreen mode Exit fullscreen mode

8. encodeURI() and encodeURIComponent()

"encodeURI()" and "encodeURIComponent()" encode URI or URI component for secure transmission.

const originalURI = "https://www.example.com/";
const encodedURI = encodeURI(originalURI);
console.log(encodeURI); // "https://www.example.com/"
Enter fullscreen mode Exit fullscreen mode

9. Error

An "Error" object represents an error in JavaScript. The base object for all error types.

try {
  throw new Error("This is an error.");
} catch (error) {
  console.error(error.message); // "This is an error."
}
Enter fullscreen mode Exit fullscreen mode

10. escape() (deprecated)

escape() is an old function used to escape characters in a string. Not recommended for modern JavaScript.

const originalString = "Hello, world!";
const escapedString = escaped(originalString);
console.log(escapedString); // "Hello %2C%20world%21"
Enter fullscreen mode Exit fullscreen mode

The results

These JavaScript properties and objects are fundamental to mastering the language. Whether you're working with data, handling errors, or manipulating numbers, understanding these concepts will provide a solid foundation for your JavaScript journey. As you progress in your coding career, you'll find these tools invaluable for building more complex and advanced applications.

Top comments (0)