Abhishek Kumar has Published 18 Articles

How to use an HTML button to call a JavaScript function?

Abhishek Kumar

Abhishek Kumar

Updated on 06-Sep-2023 21:05:15

45K+ Views

We use the onclick event attribute property of the HTML button to call a JavaScript function. The JavaScript code provided in the onclick attribute executes when the button is clicked. There are various attributes provided with the button tag in HTML that allows us to customize the button’s functionality and ... Read More

How to use nested for loop in JavaScript?

Abhishek Kumar

Abhishek Kumar

Updated on 10-Nov-2022 09:02:25

11K+ Views

We use the for loop statement of JavaScript for repeating a set of statements inside the loop body a specified number of times. A nested for loop, as the name suggests, is made up of more than one for loop one nested inside of the other. This allows us to ... Read More

How to use for...in statement to loop through an Array in JavaScript?

Abhishek Kumar

Abhishek Kumar

Updated on 10-Nov-2022 08:50:04

136 Views

We use the for...in statement of JavaScript for looping over enumerable properties of an array or object. It is a variety of for loops. Unlike other loop constructs in JavaScript, the for...in loop doesn’t have to bother about the number of iterations. This is because the iteration size is fixed ... Read More

How to use 'const' keyword in JavaScript?

Abhishek Kumar

Abhishek Kumar

Updated on 10-Nov-2022 08:47:01

3K+ Views

We use the const keyword in JavaScript to declare variables whose value can be initialized only at the time of declaration. It is similar functionality of declaring variables as the other keywords provided in JavaScript i.e. var and let. const is short for constant, meaning that the value that resides ... Read More

How to use associative array/hashing in JavaScript?

Abhishek Kumar

Abhishek Kumar

Updated on 10-Nov-2022 08:43:54

426 Views

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 ... Read More

How to use a line break in array values in JavaScript?

Abhishek Kumar

Abhishek Kumar

Updated on 10-Nov-2022 08:33:01

11K+ Views

We use the join() method of JavaScript to use a line break in array values. It allows us to concatenate all the constituent elements of an array into a single string using a common separator. The join() method in JavaScript The join() method takes as input a single separator string ... Read More

How to use Spread Syntax with arguments in JavaScript functions?

Abhishek Kumar

Abhishek Kumar

Updated on 10-Nov-2022 08:28:14

1K+ Views

We use the Spread Syntax of JavaScript to expand an array, string, or object in place. Such types of values are called iterable. This is similar to destructuring the iterable in place. Its utility in a function call allows us to extract function parameters from an iterable. In this tutorial, ... Read More

How to use JavaScript to show a confirm message?

Abhishek Kumar

Abhishek Kumar

Updated on 10-Nov-2022 08:21:44

6K+ Views

In this tutorial, we will learn how to use JavaScript to show a confirm message. We use window.confirm() method of JavaScript to show a confirm message. A confirm message is enclosed in a confirm dialog box which is a modal window. Such a window takes focus upon being created and ... Read More

How to simulate a keypress event in JavaScript?

Abhishek Kumar

Abhishek Kumar

Updated on 21-Sep-2022 08:05:35

6K+ Views

We use event handlers to simulate keypress events in JavaScript. An event in JavaScript, as the name suggests, refers to actions taken by the browser or user. An event handler is a utility that JavaScript provides, that lets the programmer implement the correct course of response to those events. We ... Read More

How to use JavaScript to set cookies for a specific page only?

Abhishek Kumar

Abhishek Kumar

Updated on 21-Sep-2022 07:58:57

2K+ Views

We can set cookies for a specific page only using JavaScript. We use the path attribute of the document.cookie property to set the cookie on a specific webpage. Cookies are small text files (4 KB) that store important information such as username, email, session id, and other preferences that help ... Read More

Advertisements