Front End Technology Articles

Page 342 of 652

How do we use throw statement in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 804 Views

In this tutorial, we will learn to use the throw statement in JavaScript. The "throw" is a reserved keyword in JavaScript that allows programmers to create user-defined exceptions. Every programmer makes errors, and sometimes users enter invalid input that causes exceptions. While JavaScript has built-in exceptions like arithmetic and index out-of-bound exceptions, programmers often need to create custom exceptions using the throw statement inside try...catch blocks. Below, we have given different examples of using the throw keyword in JavaScript. Using the throw keyword to create exception In this section, we will learn to create simple user-defined ...

Read More

What is onerror() Method in JavaScript?

Abhinaya
Abhinaya
Updated on 15-Mar-2026 2K+ Views

The onerror event handler was the first feature to facilitate error handling in JavaScript. The error event is fired on the window object whenever an exception occurs on the page. Syntax window.onerror = function(message, source, lineno, colno, error) { // Handle the error return true; // Prevents default browser error handling }; Parameters The onerror handler receives five parameters: message: Error message source: URL of the script where error occurred lineno: Line ...

Read More

How to catch exceptions in JavaScript?

Ankitha Reddy
Ankitha Reddy
Updated on 15-Mar-2026 413 Views

To catch exceptions in JavaScript, use try...catch...finally. JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions. You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors. Syntax try { // Code that may throw an exception } catch (error) { // Handle the exception } finally { // Optional - always executes } Example: Basic Exception Handling Here's a simple example demonstrating exception catching: ...

Read More

How to do basic form validation using JavaScript?

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 826 Views

JavaScript provides a way to validate form data on the client's computer before sending it to the web server. This improves user experience by catching errors immediately and reduces server load. Basic form validation includes checking that all mandatory fields are filled in and that data meets specific format requirements. It requires looping through each field in the form and validating the data. Basic Validation Methods Form validation typically checks for: Empty required fields Data format (email, phone, zip code) Data length constraints ...

Read More

How can we debug JavaScript using Firefox?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 3K+ Views

In this tutorial, we will learn to debug JavaScript code using the Firefox web browser. Debugging helps us identify and fix unknown bugs and errors in our code. Even experienced programmers encounter situations where code works fine one day but suddenly crashes the next. Don't worry if your code crashes — once you learn debugging techniques, you can fix most bugs quickly and efficiently. Let's start by creating an example with a deliberate bug to demonstrate the debugging process. Example Code with Bug In this example, we'll create a simple string comparison tool that takes two input ...

Read More

How can we debug JavaScript in Internet Explorer?

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 279 Views

Debugging JavaScript in Internet Explorer requires enabling built-in error reporting and using developer tools. While Internet Explorer is now legacy, understanding these techniques helps with maintaining older applications. Enabling Error Notifications By default, Internet Explorer shows a small error icon in the status bar when JavaScript errors occur. This icon is easily missed, so you can enable automatic error dialogs. To enable automatic error notifications: Open Internet Explorer Go to Tools → Internet Options → Advanced tab Check "Display a notification about every script error" Click OK to save changes ...

Read More

How to convert seconds to HH-MM-SS with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will learn to convert seconds to Hours, Minutes, and Seconds (HH:MM:SS) format in JavaScript. Converting seconds to a readable time format is essential for displaying durations, timers, or elapsed time in web applications. JavaScript provides several approaches to achieve this conversion. Using the toISOString() Method The toISOString() method is one of the simplest approaches to convert seconds into the standard HH:MM:SS format. This method creates a Date object and extracts the time portion. Syntax var calculatedTime = new Date(null); calculatedTime.setSeconds(seconds); var newTime = calculatedTime.toISOString().substr(11, 8); Example The ...

Read More

What is oncontextmenu event in JavaScript?

usharani
usharani
Updated on 15-Mar-2026 545 Views

The oncontextmenu event in JavaScript triggers when a user right-clicks on an element, causing the context menu to appear. This event allows you to handle right-click interactions and can be used to customize or prevent the default context menu behavior. Syntax element.oncontextmenu = function() { // Handle right-click }; // Or using addEventListener element.addEventListener('contextmenu', function(event) { // Handle right-click }); Example: Basic Context Menu Event Here's how to handle the oncontextmenu event when a user right-clicks on an element: ...

Read More

What is onmouseleave event in JavaScript?

Sreemaha
Sreemaha
Updated on 15-Mar-2026 350 Views

The onmouseleave event triggers when the mouse pointer moves out of an element. It fires only when the mouse completely leaves the element boundary. Syntax element.onmouseleave = function() { // Code to execute when mouse leaves }; // Or using addEventListener element.addEventListener('mouseleave', function() { // Code to execute }); Example: Basic Mouse Leave Event Here's how to implement the onmouseleave event: function sayHello() { ...

Read More

What is onkeydown event in JavaScript?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 463 Views

The onkeydown event in JavaScript triggers when a user presses down a key on the keyboard. This event occurs before the key is released and before the character appears in the input field, making it useful for intercepting keystrokes and implementing custom keyboard behaviors. Syntax element.onkeydown = function(event) { // Handle keydown event }; // Or using addEventListener element.addEventListener('keydown', function(event) { // Handle keydown event }); Basic Example Onkeydown Example ...

Read More
Showing 3411–3420 of 6,519 articles
« Prev 1 340 341 342 343 344 652 Next »
Advertisements