JavaScript is used everywhere, from creating the back end using environments like Node.js to creating the front end using React.js, Vue.js, etc. In JavaScript, functions are fundamental building blocks used for operations, callbacks, constructors, and many other purposes. With extensive function usage, code can become messy and hard to debug. It becomes difficult to track which functions trigger which events, making proper commenting essential for maintainability. Writing effective function comments requires following standards that other developers can easily understand and work with. Standards for Commenting Functions in JavaScript Following are essential standards for commenting functions: ... Read More
When working with iframes, you often need to call functions defined in the parent window from within the iframe. JavaScript provides several methods to achieve this cross-frame communication. Using window.parent The most common approach is using window.parent to reference the parent window: Parent Window Parent Window function displayMessage(message) { ... Read More
In JavaScript, functions typically accept a fixed number of parameters, but there are several ways to handle an unlimited number of arguments. This tutorial explores three methods to pass and process multiple arguments in JavaScript functions. Using ES5 Arguments Object The arguments object is available in all non-arrow functions and contains all arguments passed to the function, regardless of how many parameters are defined. Syntax function functionName(param1, param2) { var actualParams = functionName.length; // Number of defined parameters var totalArgs = arguments.length; ... Read More
This tutorial will teach us how to declare optional function parameters in JavaScript. While declaring the function, we pass some variables to the function definition to use it inside the function block, called function parameters. The function parameters can also be optional, which gives us the independence to pass function arguments when we call the function. Here, Arguments are the values we pass while calling the function, and parameters are the variables we pass in the function definition. What Are Optional Parameters? The optional parameter word means that you don't need to pass that parameter every time ... Read More
The multiplication assignment operator (*=) in JavaScript provides a shorthand way to multiply a variable by a value and assign the result back to the variable. Instead of writing a = a * b, you can simply use a *= b. Syntax operand1 *= operand2 // equivalent to: operand1 = operand1 * operand2 The multiplication assignment operator is a binary operator that multiplies the left operand by the right operand and stores the result in the left operand. Example 1: Basic Usage with Numbers Here's how the multiplication assignment operator works with numeric ... Read More
In this tutorial, we are going to learn how can we delay a function in JavaScript. Whenever we want to call a function after a specified amount of time than we use the delay function in JavaScript. To provide delay in JavaScript function we use a global window object named as setTimeout(). This function allows us to provide a specific delay before executing a function. The setTimeout() method mainly requires two arguments: the function which we need to execute with some delay and the time (in milliseconds) for which we want to delay the function. Syntax ... Read More
We use Object and Map classes to mimic the behavior of associative array/hashing in JavaScript. JavaScript doesn't provide an associative array built-in. The closest similar behavior we get is from the Map class in JavaScript. Let us look at them one by one. Object Class in JavaScript The object class allows us to create objects with name-value pairs. This is similar to hashing as the object knows which property is associated with what value. Syntax const obj = { name : "Abhishek", age : 22 } var name ... Read More
As we know, a URL is a web address. What is URL encoding and why do we need to encode a URL? The process of turning a string into an accurate URL format is known as URL encoding. A valid URL format only uses "alpha | digit | safe | extra | escape" characters. Only a limited selection of the normal 128 ASCII characters is permitted in URLs. Reserved characters that are not part of this set must be encoded. URL encoding increases the reliability and security of URLs. Each character that needs to be URL-encoded is encoded ... Read More
In this tutorial, we will learn how to decode a URL using JavaScript. URL is an abbreviation for Uniform Resource Locator. A URL is the address of a certain Web site. Each valid URL, in principle, links to a different resource. These resources include an HTML page, a CSS document, a picture, etc. URL encoding refers to replacing certain characters in a URL with one or more character triplets composed of the percent character "%" followed by two hexadecimal numbers. The triplet's two hexadecimal digits represent the numeric value of the replacement character. URL encoding's reverse process is ... Read More
To add a number of months to a date in JavaScript, you can use the setMonth() method combined with getMonth(). This approach automatically handles year transitions and varying month lengths. Basic Syntax date.setMonth(date.getMonth() + numberOfMonths); Example: Adding Months to Current Date var currentDate = new Date(); var monthsToAdd = 3; document.write("Original Date: ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance