Web Development Articles

Page 523 of 801

How to show prompt dialog box using JavaScript?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 975 Views

JavaScript has several built-in methods to create dialog boxes that allow users to interact with them. The prompt() method in JavaScript is one of them. The prompt dialog box is very useful when you want to pop up a text box to get user input. In this article, we'll explore how to use the prompt() method with examples. What is a Prompt Dialog Box? The prompt() method in JavaScript is used to display a dialog box that prompts the user for input. The prompt dialog box is very useful when you want to pop up a text box ...

Read More

How do you get a timestamp in JavaScript?

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

In this tutorial, we will learn to get a timestamp in JavaScript. It never happens that software developers or application developers don't require to play with date and time. In many situations, they are required to play with date and timestamp. For example, to show the time on the user's dashboard, save the time of an operation in the database. Now, let's understand what the timestamp is? The timestamp is the total number of milliseconds from the 1st January 1970 from when UNIX epochs begin. Using the timestamp, we can extract the date, day, year, month, hours, minutes, second, ...

Read More

How to use JavaScript to show a confirm message?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 7K+ 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 doesn't go out of focus until the user responds to it. Confirmation Dialog Box in JavaScript A confirm message is a yes/no message for the user that requires immediate attention. A confirmation dialog box usually gets triggered in response to some action requested by the user. This action ...

Read More

How to call a JavaScript function from an onClick event?

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

The onClick event is the most frequently used event type, which occurs when a user clicks the left button of the mouse. You can put your validation, warning etc., against this event type. Basic Syntax Click me Example: Simple onClick Function You can try to run the following code to call a JavaScript function from an onClick event: function display() { ...

Read More

What is the lifetime of JavaScript variables?

Govinda Sai
Govinda Sai
Updated on 15-Mar-2026 1K+ Views

The lifetime of a JavaScript variable refers to how long it exists in memory, from creation to destruction. Variable lifetime depends on scope and the execution context where it's declared. Local Variable Lifetime Local variables are created when a function is called and destroyed when the function completes execution. They exist only within their function scope. function checkScope() { var localVar = "I'm local"; // Created when function starts console.log(localVar); // localVar is destroyed when function ends } checkScope(); ...

Read More

How to label a block in JavaScript?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 578 Views

A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement. Labels in JavaScript provide a way to identify blocks of code, which is particularly useful for controlling nested loops with break and continue statements. Syntax Here's the basic syntax for a block statement: { // List of statements } To add a label to a block, use the following syntax: labelName: { // Statement list } Labeling Loops Labels are most commonly used ...

Read More

What is onclick event in JavaScript?

vanithasree
vanithasree
Updated on 15-Mar-2026 725 Views

The onclick event is one of the most frequently used JavaScript events. It triggers when a user clicks an HTML element, typically with the left mouse button. Syntax The onclick event can be added in three ways: // Method 1: Inline HTML attribute Click Me // Method 2: Element property element.onclick = function() { /* code */ }; // Method 3: Event listener (recommended) element.addEventListener('click', function() { /* code */ }); Example: Inline onclick The simplest approach is using the onclick attribute directly in HTML: ...

Read More

What is a block statement in JavaScript?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 1K+ Views

A block statement groups zero or more statements within curly braces {}. In languages other than JavaScript, it is known as a compound statement. Block statements are commonly used with control structures like if, for, and while. Syntax Here's the basic syntax: { // List of statements statement1; statement2; // ...more statements } Block Scoping with var vs let/const Variables declared with var do not have block scope - they are function-scoped or globally-scoped. However, let and const are block-scoped. ...

Read More

What is the difference between break with a label and without a label in JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 647 Views

In JavaScript, the break statement is used to exit loops. Without a label, it exits only the innermost loop. With a label, it can exit any labeled loop, even outer ones in nested structures. Break Without Label The break statement without a label exits only the current loop it's inside. It cannot jump out of nested loops to an outer level. Example var x = 1; document.write("Entering the loop "); ...

Read More

What is a default constructor in JavaScript?

mkotla
mkotla
Updated on 15-Mar-2026 892 Views

In JavaScript classes, if you don't define a constructor method, the JavaScript engine automatically provides a default constructor. This default constructor is implicit and handles basic object initialization. What is a Default Constructor? A default constructor is an empty constructor that JavaScript creates automatically when no explicit constructor is defined in a class. It performs minimal initialization and, for derived classes, calls the parent constructor. Syntax For base classes, the default constructor is equivalent to: constructor() {} For derived classes (classes that extend another class), the default constructor is: constructor(...args) ...

Read More
Showing 5221–5230 of 8,010 articles
« Prev 1 521 522 523 524 525 801 Next »
Advertisements