Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 505 of 534
How do you get a timestamp in JavaScript?
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 MoreHow to use JavaScript to show a confirm message?
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 MoreHow to call a JavaScript function from an onClick event?
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 MoreWhat is the lifetime of JavaScript variables?
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 MoreHow to label a block in JavaScript?
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 MoreWhat is onclick event in JavaScript?
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 MoreWhat is a block statement in JavaScript?
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 MoreWhat is the difference between break with a label and without a label in JavaScript?
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 MoreWhat is a default constructor in JavaScript?
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 MoreHow to show if...else statement using a flowchart in JavaScript?
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