Mohit Panchasara

Mohit Panchasara

67 Articles Published

Articles by Mohit Panchasara

Page 2 of 7

How to record and play audio in JavaScript?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 6K+ Views

Are you also willing to add a custom audio recording feature to your web application? If yes, you are in the right place, as we will learn to record and play audio using JavaScript in this tutorial. Some applications like Discord allow you to record the audio and store it inside that to play it anytime. The recorded audio can also be used as a meme for fun, alerts in the discord meetings, etc. We can also use the MediaRecorder API of JavaScript to add the recording audio feature to our web application. Here, we will learn a ...

Read More

How to stop event propagation with inline onclick attribute in JavaScript?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 3K+ Views

Event propagation in JavaScript causes events to bubble up from child elements to their parents. When you have nested elements with click handlers, clicking a child element triggers both the child and parent handlers. The stopPropagation() method prevents this bubbling behavior. Understanding Event Propagation Let's see how event propagation works with nested elements: .parent-div { width: 300px; height: 150px; ...

Read More

How to terminate a script in JavaScript?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 16K+ Views

The termination of the script means that it stops executing the JavaScript code. In some emergency cases, developers require to abort the execution of JavaScript code in the middle while the script is executing. Also, we can use the if-else statement to decide when to terminate the script execution and when to continue. Here, we will learn different ways to terminate the script midway. Use the Return Statement The return statement is used to terminate the execution of any code inside the function. Once we execute the return statement inside the function, the code written after the ...

Read More

How to test a value x against predicate function and returns fn(x) or x in JavaScript?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 149 Views

Testing a value x against a predicate function means checking if x meets a specific condition. If the condition is true, we apply a transformation function to x and return the result. Otherwise, we return the original value x unchanged. Syntax The basic syntax uses the ternary operator to test a value against a predicate function: let result = predicate(x) ? operation(x) : x; Where predicate(x) returns true/false, and operation(x) transforms the value when the predicate passes. Basic Example Here's a simple example that squares numbers greater than 5, otherwise returns the ...

Read More

How to uniquely identify computers visiting web site in JavaScript?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 821 Views

Whenever we create any application or website, we need to uniquely identify computers visiting the website. There are many benefits to uniquely identifying computers. For example, you can provide free trial services when a user visits your website for the first time from a new device. When they visit again, you can ask users to upgrade to premium or subscribe to your application. Here, we will use cookies to identify computers visiting our website. What are Cookies? Cookies allow developers to store user information in the browser. We can send data from the server to the ...

Read More

How to upload file without form using JavaScript?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 7K+ Views

Sometimes, developers need to upload files without creating traditional HTML forms. This is useful for drag-and-drop interfaces, single-click uploads, or when building custom file upload components. In this tutorial, we'll explore methods to upload files directly using JavaScript. Using FormData() Object and AJAX Request The FormData object allows us to store file data in key-value pairs, similar to form submissions. We can capture files from HTML input elements and send them to the server using AJAX without wrapping them in a form. Syntax let formData = new FormData(); formData.append("file", uploadedFile); $.ajax({ ...

Read More

How to uncheck a radio button using JavaScript/jQuery?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 30K+ Views

Sometimes, we require to uncheck a radio button using JavaScript or jQuery. For example, we use the radio button in the form. When the user presses the clear form button, we need to uncheck all radio buttons and allow again users to choose any option from the radio button. In this tutorial, we will learn various methods to uncheck single or multiple radio buttons using jQuery or JavaScript. Using JavaScript to Uncheck Radio Button We can access the radio button in JavaScript using id, tag, name or other ways. After that, we can uncheck the radio button's ...

Read More

How to skip over an element in .map()?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 17K+ Views

In JavaScript, we sometimes need to skip array elements while using the map() method. For example, we might want to map values from one array to another after performing mathematical operations only on finite values, or transform strings that meet specific criteria. Here are three effective approaches to skip over array elements while using the map() method. Using if-else Statement In the array.map() method, we can use an if-else statement to conditionally process elements. If an element meets our condition, we return the transformed value; otherwise, we return null or undefined. Syntax array.map((element) => ...

Read More

How to transform a JavaScript iterator into an array?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 2K+ Views

In JavaScript, iterators are objects that implement the iterator protocol, allowing you to traverse through collections like Sets, Maps, or custom iterables. Unlike arrays, you cannot access iterator elements by index, so converting iterators to arrays is often necessary for easier manipulation. Here are three effective methods to transform JavaScript iterators into arrays. Using the for-of Loop The for-of loop iterates through each element of an iterator. Inside the loop, you can access elements and push them to an array using the push() method. Syntax for (let element of iterator) { ...

Read More

How to transform a String into a function in JavaScript?

Mohit Panchasara
Mohit Panchasara
Updated on 15-Mar-2026 3K+ Views

We have given a string and need to convert it into a function in JavaScript. Sometimes, we get mathematical or function expressions in the form of the string, and executing that expression, requires converting strings into the function expression. In this tutorial, we will learn different approaches to converting the given string into a functional or mathematical expression. Use the eval() method The eval() method takes the expression as a parameter and evaluates the expression. For example, if we pass the '2 + 2' string as a parameter of the eval() method, it returns 4 as it evaluates ...

Read More
Showing 11–20 of 67 articles
« Prev 1 2 3 4 5 7 Next »
Advertisements