Javascript Articles

Page 505 of 534

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 563 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 690 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 621 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 875 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

How to show if...else statement using a flowchart in JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 358 Views

The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Let's see how to show if...else statement using flowchart in JavaScript. If...Else Statement Flowchart Start Condition? True False ...

Read More
Showing 5041–5050 of 5,340 articles
« Prev 1 503 504 505 506 507 534 Next »
Advertisements