Temporal : Cookbook

Running the cookbook files Running cookbook files: see instructions in ../polyfill/README.md Frequently Asked Questions These are some of the most common tasks that people ask questions about on StackOverflow with legacy Date. Here’s how they would look using Temporal. Current date and time How to get the current date and time in the local time zone? /** *… Continue reading Temporal : Cookbook

Temporal : General Overview

Introduction Date has been a long-standing pain point in ECMAScript. This is a proposal for Temporal, a global Object that acts as a top-level namespace (like Math), that brings a modern date/time API to the ECMAScript language. For a detailed look at some of the problems with Date, and the motivations for Temporal, see: Fixing JavaScript Date. Temporal fixes these problems by:… Continue reading Temporal : General Overview

Make API call (POST Request) using JavaScript in browser’s debug console

const xhr = new XMLHttpRequest(); const url = “END_POINT”; const data = {};//Request Body xhr.open(“POST”, url, true); xhr.setRequestHeader(“Content-Type”, “application/json”); xhr.onreadystatechange = function () {     if (xhr.readyState === 4 && xhr.status === 200) {         console.log(xhr.responseText);     } }; xhr.send(data);

Why Fetch Promise Doesn’t Reject on Error Responses

The problem If you’ve been using the fetch() function in the browser or modern versions of Node.js, you know that it returns a Promise. 1fetch(request).then((response) => { 2 // Handle the response. 3}) You also know that promises in JavaScript reject if there’s been an error while resolving them. But, for some obscure reason, the Promise returned from fetch() never rejects… Continue reading Why Fetch Promise Doesn’t Reject on Error Responses

Object.keys

Object.keys() returns an array whose elements are strings corresponding to the enumerable string-keyed property names found directly upon object. This is the same as iterating with a for…in loop, except that a for…in loop enumerates properties in the prototype chain as well. The order of the array returned by Object.keys() is the same as that… Continue reading Object.keys

Parse XML to JSON without using any DOM or NetSuite functions

Following is a library/function to Parse XML data to JSON without using any DOM or NetSuite functions Library File :     const xml2json = {         parser: function (xmlcode, ignoretags = [], debug = false) {             xmlcode = xmlcode.replace(/s*/>/g, ‘/>’);          … Continue reading Parse XML to JSON without using any DOM or NetSuite functions

JavaScript — What’s new with ECMAScript® 2024 (ES15) — In Depth Guide

Discovering new functionality in programming languages is like the holidays or a birthday — it’s an exciting time filled with anticipation and the joy of exploring new gifts. With the proposed features of ES2024®, developers are on the brink of unwrapping a variety of enhancements that promise to make coding in JavaScript more efficient, readable, and… Continue reading JavaScript — What’s new with ECMAScript® 2024 (ES15) — In Depth Guide

You don’t need JavaScript for that

The rule of least power It’s one of the core principles of web development and it means that you should Choose the least powerful language suitable for a given purpose. On the web this means preferring HTML over CSS, and then CSS over JS. JS is the most versatile language out of the three because you’re… Continue reading You don’t need JavaScript for that

Calculate total from an array of object contains similar items.

Function to find the total from an array of object if it contains similar items. var groupedByItem = arr.reduce(function (result, current) {    var item = current.Item;    if (!result[item]) {       result[item] = {          Type: current.Type,          Item: item,          TotalQuantity: 0       };    }    result[item].TotalQuantity += parseInt(current.Quantity);    return result;… Continue reading Calculate total from an array of object contains similar items.