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 Saurabh Jaiswal
Page 3 of 4
How to add 2 hours to a JavaScript Date object?
In this tutorial, we will learn how to add 2 hours to a JavaScript Date object. Here we will discuss two methods which are following. Using the getTime() Method Using the setHours() Method Using the getTime() Method JavaScript date getTime() method returns the numeric value corresponding to the time for the specified date according to universal time. The value returned by the getTime() method is the number of milliseconds since 1 January 1970 at 00:00:00. Syntax Date.getTime() Approach To add 2 hours to the Date Object first, we get ...
Read MoreHow null is converted to Boolean in JavaScript?
In JavaScript, null is a primitive value that represents an intentional absence of any object value. When converting null to Boolean, it always evaluates to false because null is considered a falsy value in JavaScript. Understanding Falsy Values In JavaScript, null is one of the falsy values along with undefined, 0, "" (empty string), NaN, and false. All falsy values convert to false when used in Boolean contexts. Using the Boolean() Function The Boolean() function converts any value to its Boolean equivalent. For null, it always returns false. Syntax Boolean(null) Example ...
Read MoreHow is NaN converted to Boolean in JavaScript?
In JavaScript, NaN (Not a Number) is a special numeric value that represents an invalid number. When converted to Boolean, NaN is always considered a falsy value. This article explores three methods to convert NaN to Boolean. Using the Boolean() Function Using the !! Operator Using the NOT Operator and isNaN() Method Understanding NaN as a Falsy Value In JavaScript, NaN is one of the falsy values (along with false, 0, "", null, and undefined). This means it always converts to false in Boolean contexts. Using the Boolean() Function The Boolean() function converts ...
Read MoreHow to add hours and minutes to a date with JavaScript?
In this tutorial, we will learn how to add hours and minutes to a date with JavaScript. We have multiple methods to achieve this which are the following. Add hours using the setHours() Method. Add minutes using the setMinutes() Method. Add hours or minutes with the getTime() Method. Add hours using the setHours Method JavaScript date setHours() method sets the hours for a specified date according to local time. Syntax Following is the syntax to apply the setHours() method to add ...
Read MoreHow to add rows to a table using JavaScript DOM?
We will learn how to add a row to a table using JavaScript DOM. To achieve this, we have multiple methods. Some of them are the following. Using the insertRow() method By creating the new Element Using the insertRow() Method The insertRow() method is used to insert a new row at a specified position in the table. It creates a new element and inserts it into the table. This takes a number as a parameter that specifies the position of the table. If we do not pass any ...
Read MoreHow to calculate the nth root of a number in JavaScript?
In JavaScript, calculating the nth root of a number requires understanding the mathematical rules for roots and applying appropriate methods. We'll explore two primary approaches: using Math.pow() and using logarithms. Understanding nth Root Rules Before calculating nth roots, it's important to understand when solutions exist: If the number is positive and the root is even, there are two solutions (positive and negative). Example: 2nd root of 16 is +4 and -4 If the number is positive and the root is odd, there is one positive solution. Example: 3rd root of 27 is 3 If the number ...
Read MoreWhat is a NaN property of a Number object in JavaScript?
In JavaScript, the NaN property is a special value that represents "Not a Number". It is a property of the Number object and can be accessed using Number.NaN. The NaN property is usually produced as a result of an operation that cannot produce a meaningful result. For example, dividing 0 by 0 or trying to parse an invalid number will both produce NaN. Common Operations That Produce NaN console.log(Math.sqrt(-1)); // NaN console.log(0/0); // NaN console.log(parseInt("foo")); // NaN console.log("hello" * 2); ...
Read MoreHow to access cookies using document object in JavaScript?
In JavaScript, you can access and read cookies using the document.cookie property. This property returns a string containing all cookies stored in the browser for the current domain. The document.cookie string contains a list of name=value pairs separated by semicolons, where each name represents a cookie name and its corresponding value is the cookie's string value. In this article, we will learn how to access cookies using the document object in JavaScript. Syntax document.cookie Return Value: A string containing all cookies for the current domain, formatted as semicolon-separated name=value pairs. Reading All ...
Read MoreHow to call jQuery function with JavaScript function?
JavaScript is the core of any website, it adds functionalities to a website, make the overall website responsive. But in JavaScript, it is hard to select an element and add different functions like toggling an element, fade-in an element, and more. jQuery provides many methods for making it easy to add functionality to a website like fade-in, fade-out, hide, show, toggle, etc. Concatenating jQuery and JavaScript makes it easy to use the jQuery function in JavaScript function whenever needed, instead of calling them separately. Syntax To call a jQuery function with a JavaScript function, you can ...
Read MoreWhat is a standard for commenting a function in JavaScript?
JavaScript is used everywhere, from creating the back end using environments like Node.js to creating the front end using React.js, Vue.js, etc. In JavaScript, functions are fundamental building blocks used for operations, callbacks, constructors, and many other purposes. With extensive function usage, code can become messy and hard to debug. It becomes difficult to track which functions trigger which events, making proper commenting essential for maintainability. Writing effective function comments requires following standards that other developers can easily understand and work with. Standards for Commenting Functions in JavaScript Following are essential standards for commenting functions: ...
Read More