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
Articles by Shubham Vora
Page 25 of 80
How to get the number of seconds between two Dates in JavaScript?
In JavaScript, calculating the difference between two dates in seconds is a common requirement for timers, age calculators, and duration displays. JavaScript Date objects provide millisecond precision, which we can easily convert to seconds. Using the getTime() Method The getTime() method returns the number of milliseconds since January 1, 1970 UTC. By subtracting two timestamps and dividing by 1000, we get the difference in seconds. Syntax let date1 = new Date("Aug 12, 2022 19:45:25"); let date2 = new Date("Aug 14, 2022 19:45:25"); let seconds = Math.abs(date1.getTime() - date2.getTime()) / 1000; Example ...
Read MoreHow to set the style of the top border with JavaScript?
In this tutorial, we shall learn to set the style of the top border with JavaScript. To set the style of the top border in JavaScript, use the borderTopStyle property. This property allows you to dynamically change the visual appearance of an element's top border. Let us discuss the property available in JavaScript to achieve this in brief. Using the borderTopStyle Property With the Style borderTopStyle property, we can set or return the style of the top border of an element. Syntax Following is the syntax to set the style of the top border using ...
Read MoreHow to convert a MySQL date to JavaScript date?
In this tutorial, we will learn to convert the MySQL date to JavaScript date. The MySQL date is not different from the regular date, but its format or syntax is different, which we need to convert into the format of a normal date. The general syntax of the MySQL date is YYYY-MM-DD HH:mm:ss. So, we need to convert the given MySQL date string syntax to normal date syntax. We will have two approaches to converting the MySQL date to the JavaScript date. Using the replace() Method Using the split() Method ...
Read MoreHow to get first and last date of the current month with JavaScript?
In this tutorial, we will look at how to get the first and last date of the current month using JavaScript. Working with dates is common in web development, especially when building calendars, date pickers, or time-based features. JavaScript provides built-in methods to handle dates, and there are also external libraries that make date manipulation easier. Following are the approaches to get the first and last date of the month using JavaScript − Using a Date Object Using the Moment.js Library Using a Date Object JavaScript's built-in ...
Read MoreRegular expression to match numbers only in JavaScript?
In this tutorial, we will learn regular expressions to match numbers only in JavaScript. Data validation is essential for web applications. We often need to ensure users provide correct input — for example, phone numbers should contain only digits, or credit card fields should accept numbers only. Regular expressions provide a powerful way to validate and extract numeric data from strings. They use patterns to match specific character types and return the matched results. Understanding Regular Expression Patterns A regular expression consists of a pattern and optional modifiers. For matching numbers, we use: \d ...
Read MoreWhat are the three types of errors I can expect in my JavaScript script?
In this tutorial, let us discuss the three types of errors we can expect in our JavaScript code. Errors are statements that block the execution of the program. During the compilation and execution of JavaScript programs, three types of errors can occur: syntax errors, runtime errors, and logical errors. Syntax Errors Syntax errors are the most common errors that occur when the JavaScript engine cannot understand the code due to incorrect syntax. These errors happen during the parsing phase before code execution begins. For example, using a semicolon instead of a colon in an object declaration ...
Read MoreHow to set the style of the right border with JavaScript?
In this tutorial, we will learn to set a style of the right border with JavaScript. To set the style of the right border in JavaScript, use the borderRightStyle property. Set the style of the right border using this property. We can apply borders to an element from any side or all sides. We can customize that border on any side. Every edge of a border has a specific property that can use only for that edge. We can provide three parameters like style, color, and width for creating a border. CSS is used to do such tasks. But, ...
Read MoreHow do we use throw statement in JavaScript?
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 MoreHow to set the width of the right border with JavaScript?
This tutorial will teach us to set the width of the right border with JavaScript. To set the width of the right border, use the borderRightWidth property. Set the width of the right border using this property. We can also apply the borderWidth to set the right border. Borders are used on various elements on a webpage. They display the boundaries of an element. We can apply the borders to all sides of an element. There are different properties to set different sides of a border. For a static border, generally, CSS is used. But to change it dynamically, ...
Read MoreIs there a way to print all methods of an object in JavaScript?
In JavaScript, methods are object properties that contain functions. Sometimes you need to inspect an object to discover all its available methods. This tutorial shows how to print all methods of an object using different approaches. A method is simply a function stored as an object property. When you call obj.methodName(), you're executing the function stored in that property. JavaScript provides several ways to discover these function properties. Using Object.getOwnPropertyNames() Method The Object.getOwnPropertyNames() method returns an array of all properties (including non-enumerable ones) found directly on an object. We can filter this array to find only function ...
Read More