Javascript Articles - Page 355 of 534

Passing empty parameter to a method in JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:28:12

1K+ Views

Following is the code passing empty parameter to a method in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Passing empty parameter to a method Click here Click on the above button to call multiply function and pass empty parameters to it    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    function multiply(a = 2, b = 4) {       return a * b;    }    BtnEle.addEventListener("click", () => {       resEle.innerHTML = "The multiplication of numbers = " + multiply();    }); OutputOn clicking the ‘Click here’ button −

How to borrow methods in JavaScript?

AmitDiwan
Updated on 17-Jul-2020 07:24:59

195 Views

The call(), apply() and bind() are used to borrow methods in JavaScript.Following is the code for borrowing methods in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Borrowing a method in JavaScript CLICK HERE Click on the above button to borrow the welcome method of object obj ... Read More

Escape characters in JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:12:58

9K+ Views

Escape characters are characters that can be interpreted in some alternate way then what we intended to. To print these characters as it is, include backslash ‘\’ in front of them. Following are the escape characters in JavaScript −CodeResult\bBackspace\fForm FeedNew Line\rCarriage Return\tHorizontal Tabulator\vVertical Tabulator\'Single quote\"Double quote\BackslashFollowing is the code implement escape character Backslash in javaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;    } Escape characters in JavaScript ... Read More

Default exports vs Named exports in JavaScript

AmitDiwan
Updated on 16-Aug-2023 16:35:06

1K+ Views

In this article, we will learn the difference between default exports and named exports in javascript, and how we can use them to effectively organize our code structure. In javascript, we can use default exports and named exports so as to have separate files or modules for separate pieces of code. This helps in enhancing code readability and tree shaking to a great extent. Default exports Named exports A default export allows us to export a single value or function as the default export of a module. A named export allows us to export multiple values ... Read More

Arrays vs Set in JavaScript.

Alshifa Hasnain
Updated on 29-Mar-2025 02:56:35

3K+ Views

In this article, we will learn about the difference between an array and a set in JavaScript. Arrays are used to store ordered collections of elements, whereas in Sets, we can store only unique values. What is an Array?  An Array is an ordered, indexed collection of values in JavaScript. It allows duplicate values and provides various built-in methods to manipulate elements. Syntax let numbers= [1, 2, 3, 4, 5]; What is a Set? A Set is an unordered collection of unique values in JavaScript. Unlike arrays, a Set does not allow duplicate values. Syntax let numbers= new Set([1, 2, ... Read More

How to convert Array to Set in JavaScript?

AmitDiwan
Updated on 16-Aug-2023 15:33:12

870 Views

This tutorial will teach you how to eliminate duplicate values from an array of items in Javascript by converting an array to a set. When storing distinct values from a collection of data in javascript, we can utilise the Set data structure to get rid of duplicate values. When we wish to eliminate duplicates from our data or take advantage of the special features offered by Sets data structure, converting an array to a Set can be helpful. Let’s look at some of the examples and methods to understand the concept better − Example 1 - Using the Set Constructor ... Read More

How to use named arguments in JavaScript functions?

AmitDiwan
Updated on 16-Aug-2023 15:58:15

2K+ Views

In this article, we will learn how to use named arguments in javascript, and how we can use it to significantly enhance code readability and maintainability. Javascript allows us to use named arguments, which eliminate the need for the order of parameters to matter during function execution. We may then access the arguments by name inside the function definitions. Let’s look at some of the examples and methods to understand the concept better − Example 1 - Passing Objects as Arguments We can pass an object as an argument to the function to achieve named−argument functionality. This uses the ... Read More

Exports & Imports in JavaScript

AmitDiwan
Updated on 16-Aug-2023 15:55:32

441 Views

We will learn how to utilise imports and exports in javascript in this post, as well as how to use them to break our code into different modules in order to better organise it. To facilitate modular development in programming, which enables us to organise our code into reusable modules, JavaScript provides exports and imports. To achieve this sharing and reusability of code, we can use different types of exports and imports. Exports allow us to make functions, variables, objects, or any values available outside of a module. By marking components as exports, we can expose them for use in ... Read More

How do JavaScript primitive/object types passed in functions?

AmitDiwan
Updated on 16-Jul-2020 14:01:21

260 Views

Following is the code to pass JavaScript primitive and object types to function −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Passing primitive/object types to function Click here Click on the above button to pass primitive and object to a function and call it    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let person = { ... Read More

How to read a cookie using JavaScript?

AmitDiwan
Updated on 16-Aug-2023 15:40:37

6K+ Views

In this article, we will learn how to read cookies in javascript, and how we can use it to implement certain features such as user tracking, user preference, personalized experience, etc. Cookies are small pieces of data stored in a user's web browser. In javascript, we can read cookies using document's cookie property and extract the desired information using destructuring. Let’s look at some of the examples to understand the concept better − Example 1 - Reading All Cookies In this example, we will − read all cookies by accessing the document.cookie property and log them to the console. ... Read More

Advertisements