JavaScript provides several methods to convert images to Data URI (Base64) format. A Data URI is a string representation of an image that can be embedded directly in HTML or CSS. This tutorial covers two main approaches: using Canvas API for image URLs and FileReader API for local files. Method 1: Converting Image URL to Data URI Using Canvas This method uses the HTML5 Canvas API to convert an image from a URL to a Base64 Data URI string. Convert Image URL to Data URI ... Read More
String interpolation in JavaScript is a process in which expressions and variables are embedded directly into strings. This is achieved using template literals (backticks) with placeholder syntax ${}, making code more readable and maintainable than traditional string concatenation. Template literals use backticks (`) instead of quotes and allow expressions to be embedded using ${expression} syntax. This enables dynamic content insertion, mathematical calculations, and complex expressions within strings. Syntax `string text ${expression} more text` The expression inside ${} can be variables, function calls, mathematical operations, or any valid JavaScript expression that returns a value. ... Read More
In JavaScript, objects are collections of key-value pairs. The properties of the object are the keys and are denoted with strings. The value of the key is the value of the property of the given object. Types of Object Copying There are 2 types of copying objects: shallow copy and deep copy. Shallow Copy In shallow copy, an object is copied at the top level only. If the object contains nested objects, only the references are copied, not the actual nested objects. Example Following is an example of shallow copy using Object.assign(): ... Read More
The Lodash library is a JavaScript utility library that provides helpful functions for working with arrays, strings, objects, numbers, and more. This article compares three important object merging methods: Object.assign(), _.extend(), and _.merge(). The Object.assign() Method Object.assign() is a native JavaScript method that performs shallow copying of enumerable properties from source objects to a target object. It modifies the target object and returns it. Syntax Object.assign(target, source1, source2, ...) Example var employee = { emp_name: "Abdul Rawoof", company: "Tutorials Point", salary: 18000, ... Read More
The .stack property in JavaScript provides detailed information about errors, including the error type, message, and call stack trace. It shows where the error occurred and the sequence of function calls that led to the error. The stack property is available on Error objects and contains a string representation of the stack trace. This is extremely useful for debugging as it shows the exact location and path of execution when an error occurs. Format of Error Stack The stack trace format typically displays: First line: Error type and message Subsequent lines: Function call stack with file ... Read More
JavaScript has two primitive values that represent "nothing": null and undefined. Both indicate the absence of a meaningful value, but they have distinct purposes and behaviors. Undefined A variable is undefined when it has been declared but not assigned a value, or when a function doesn't explicitly return anything. JavaScript automatically assigns undefined in these cases. Example 1 - Variable Declaration When a variable is declared but not assigned a value: var str; console.log('The value of given variable is:', str); The value of given variable is: undefined Example 2 ... Read More
In JavaScript, objects are reference types, meaning simple assignment creates a reference to the original object, not a copy. Deep cloning creates a completely independent copy with separate memory allocation for nested objects and arrays. Understanding Deep vs Shallow Cloning Shallow cloning copies only the top-level properties, while deep cloning recursively copies all nested objects. Methods like spread operator and Object.assign() only perform shallow copies. Using JSON.parse() and JSON.stringify() (Most Common) The most efficient and widely-used approach combines JSON.stringify() to convert the object to a string, then JSON.parse() to create a new object from that string. ... Read More
In JavaScript, objects are collections of key-value pairs where properties are identified by string keys. There are several ways to duplicate object properties from one object to another, each with different characteristics for handling nested objects and references. Using Spread Operator (...) The spread operator creates a shallow copy of an object by spreading its enumerable properties into a new object. It's represented by three dots (...) and is the most modern and readable approach. Example 1 This example demonstrates how the spread operator copies objects in JavaScript: var employee = { ... Read More
In JavaScript, window.onload and $(document).ready() are two different methods for executing code when a page loads, each with distinct timing and behavior. Window.onload The window.onload method executes after the entire web page has completely loaded, including all DOM elements, stylesheets, images, and other external resources. It only allows one function assignment — subsequent assignments will overwrite previous ones. Syntax window.onload = function() { // Code executes after everything loads }; window.onload = (event) => { // Arrow function syntax }; Example: Window.onload Behavior ... Read More
The operating system of the client machine can be detected using JavaScript navigator properties. This is useful for providing platform-specific functionality or displaying system information to users. Using navigator.appVersion The navigator.appVersion property returns a string containing browser and operating system information. This method allows you to parse the version string to identify the OS. Syntax navigator.appVersion Example 1: Detecting Operating System This example demonstrates how to detect the client's operating system using navigator.appVersion: Click to get the operating system ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance