Javascript Articles

Page 417 of 534

How to allocate memory in Javascript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 595 Views

Regardless of the programming language, memory life cycle is pretty much always the same: Allocate the memory you need Use the allocated memory (read, write) Release the allocated memory when it is not needed anymore The second part is explicit in all languages. Use of allocated memory needs to be done by the developer. The first and last parts are explicit in low-level languages like C but are mostly implicit in high-level languages like JavaScript. Hence there is no explicit way to allocate or free up memory in JavaScript. Just initializing objects allocates memory ...

Read More

How to convert MySQL DATETIME value to JSON format in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 719 Views

To convert MySQL DATETIME values to JSON format in JavaScript, you can parse the datetime string into a Date object and then use JSON.stringify() to convert it to JSON. This is useful when working with MySQL data in web applications. Understanding MySQL DATETIME Format MySQL DATETIME format is typically YYYY-MM-DD HH:MM:SS. JavaScript's Date constructor can parse various date formats, making conversion straightforward. Method 1: Converting to JSON Object with Individual Components This approach extracts individual date components and creates a structured JSON object: // Simulate MySQL DATETIME string var mySQLDateTime = new Date("2019-09-06 ...

Read More

Advanced JavaScript Backend Basics

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 829 Views

JavaScript is a lightweight, interpreted programming language primarily used for web development. Each browser has its own JavaScript engine that enables proper code execution. Common browsers and their JavaScript engines include: SpiderMonkey for Firefox V8 for Google Chrome JavaScriptCore for Safari Chakra for Microsoft Internet Explorer/Edge To standardize JavaScript across browsers, the ECMA (European Computer Manufacturers Association) sets official standards for the language. How JavaScript Engine Works JavaScript engines execute code in two distinct phases to ensure proper functionality across all browsers: ...

Read More

Write the dependencies of backbone.js in javascript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 275 Views

Backbone.js is a lightweight JavaScript framework that requires specific dependencies to function properly. Understanding these dependencies is crucial for setting up and working with Backbone.js applications. Hard Dependency The only hard dependency (without which Backbone.js won't work at all) is Underscore.js. Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. // Including Underscore.js is mandatory Optional Dependencies There are other dependencies required as you proceed to use more advanced features of Backbone.js: jQuery or ...

Read More

What are the differences between lodash and underscore?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 1K+ Views

Lodash and Underscore are both utility libraries that make JavaScript easier by providing utils that make working with arrays, numbers, objects, strings, etc. much easier. These libraries are great for: Iterating arrays, objects, & strings Manipulating & testing values Creating composite functions They are both functional libraries. Lodash is a fork of Underscore, and still follows Underscore's API enough to allow it to serve as a drop-in replacement. But under the hood, it's been completely rewritten, and it's also added a number of features and functions that ...

Read More

Safely Accessing Deeply Nested Values In JavaScript

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 458 Views

Accessing deeply nested properties in JavaScript can cause errors if intermediate properties don't exist. Modern JavaScript provides several safe approaches to handle this common problem. The Problem with Direct Access Directly accessing nested properties throws errors when intermediate properties are undefined: let obj = { user: { profile: { name: "John" } } }; console.log(obj.user.profile.name); // "John" - ...

Read More

Safely setting object properties with dot notation strings in JavaScript

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 1K+ Views

In JavaScript, safely setting nested object properties can be challenging because accessing undefined nested paths throws errors. This article covers two approaches: using Lodash's set method and creating a custom solution. Using Lodash's set() Method Lodash provides a safe set method that handles nested property assignment without throwing errors, even if intermediate properties don't exist. let _ = require("lodash"); let obj = { a: { b: { foo: "test" ...

Read More

JavaScript Encapsulation using Anonymous Functions

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 453 Views

Object-oriented programming languages allow data hiding using private fields. They use these to hide the internals of classes. In JavaScript there is no built-in support to hide/encapsulate the inner workings, but we can achieve encapsulation using anonymous functions. Anonymous functions, particularly when used as Immediately Invoked Function Expressions (IIFEs), can create private scopes that prevent global namespace pollution and provide encapsulation. The Problem: Global Namespace Pollution When we declare variables and functions in the global scope, they become accessible everywhere and can cause naming conflicts: const HIDDEN_CONST = 100; function fnWeWantToHide(x, y) { ...

Read More

How to programmatically set the value of a select box element using JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 1K+ Views

We can set the value of a select box using JavaScript by accessing the element and changing its value property. This is useful for dynamically updating form selections based on user interactions or application state. HTML Setup First, let's create a select element with multiple options: Select Apple Strawberry Cherry Guava Method 1: Using querySelector and value Property The most common approach is to use querySelector to find the element and ...

Read More

How to delete a localStorage item when the browser window/tab is closed?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 2K+ Views

To clear localStorage data when a browser window or tab is closed, you can use the beforeunload or unload events. However, there are important limitations and better alternatives to consider. Using beforeunload Event The beforeunload event fires before the page unloads, giving you a chance to clean up localStorage: window.addEventListener('beforeunload', function() { // Clear specific item localStorage.removeItem('userSession'); // Or clear all localStorage localStorage.clear(); console.log('localStorage cleared ...

Read More
Showing 4161–4170 of 5,340 articles
« Prev 1 415 416 417 418 419 534 Next »
Advertisements