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 292 of 534
How 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 MoreHow to use JavaScript to check if a number has a decimal place or it's a whole number?
In JavaScript, determining whether a number is a whole number or has decimal places is a common requirement. This tutorial explores three effective methods to accomplish this task using both built-in JavaScript methods and custom functions. The following methods are available to check if a number is decimal or whole: Using the Math.floor() Method Using the Number.isInteger() Method Using a Custom isDecimal() Function Using Math.floor() Method The Math.floor() method returns the largest integer less than or equal to a given number. By comparing the original number with its ...
Read MoreHow to check if a variable is boolean in JavaScript?
In JavaScript, determining if a variable is a boolean can be tricky because of type coercion. When using the equality operator (==), JavaScript converts values, so true == "true" returns true even though they're different types. To accurately check boolean types, we need specific methods. Here are three reliable approaches to check if a variable is a boolean: Using the typeof operator Using the strict equality operator (===) Using Object.prototype.toString.call() Using the typeof Operator The typeof operator returns a string indicating the ...
Read MoreHow to initialize a boolean array in JavaScript?
In JavaScript, boolean arrays are useful for storing true/false values. You can initialize them using several methods, each with different advantages depending on your needs. We can initialize a boolean array in JavaScript in three ways: Using the fill() Method Using the Array.from() Method Using the for Loop Using the fill() Method The fill() method is the simplest way to create a boolean array with all elements having the same value. It fills all array positions with a static value from start to end. ...
Read MoreHow to convert a string into upper case using JavaScript?
In JavaScript, converting strings to uppercase is a common task needed for data validation, form processing, and ensuring consistent text formatting. JavaScript provides a built-in method for this purpose, and you can also create custom implementations to understand the underlying mechanism. This tutorial covers different approaches to convert strings to uppercase, from the standard built-in method to creating custom functions for educational purposes. Using the String toUpperCase() Method The toUpperCase() method is the most straightforward way to convert strings to uppercase. It's a built-in JavaScript method that works on any string value and returns a new string ...
Read MoreHow to change the font size of a text using JavaScript?
In this tutorial, programmers will learn to change the font size of text using JavaScript. Many applications allow users to change the font size according to their requirements. We need to change the default font size using JavaScript to achieve that. Before we move ahead with the tutorial, let's learn what values we can assign to the font size. Different Values for Font Size We can assign the below values to the font size of any element. Every value changes the font size differently: xx-large | x-large | large | medium | small ...
Read MoreUsage of font-size property in CSS
The font-size property in CSS controls the size of text elements. It accepts various units and keywords to specify how large or small text should appear on a webpage. Syntax font-size: value; Font Size Values The font-size property accepts several types of values: Absolute keywords: xx-small, x-small, small, medium, large, x-large, xx-large Relative keywords: smaller, larger Length units: pixels (px), em, rem, points (pt) Percentage: relative to parent element's font size Example: Different Font Size Values ...
Read MoreHow to create a strikethrough text using JavaScript?
To create a strikethrough text with JavaScript, you can use several methods. The legacy strike() method wraps text in deprecated tags, while modern approaches use CSS styling for better compatibility. Using the Legacy strike() Method The strike() method creates strikethrough text by wrapping it in tags. However, this method is deprecated and not recommended for new projects. JavaScript String strike() Method var str = "Demo Text"; ...
Read MoreSet the font weight with CSS
The font-weight property controls how bold or light text appears. It accepts keyword values like normal and bold, or numeric values from 100 to 900. Syntax font-weight: normal | bold | bolder | lighter | 100-900; Font Weight Values Value Description Numeric Equivalent normal Regular text weight 400 bold Bold text weight 700 bolder Bolder than parent element Relative lighter Lighter than parent element Relative Example: Different Font Weights Font Weight Example ...
Read MoreHow to change string to be displayed as a subscript using JavaScript?
In this tutorial, we will learn to display strings as subscripts using JavaScript. A subscript is text that appears smaller and positioned below the baseline of normal text. For example, in H2O, the "2" is a subscript. Subscripts are commonly used in mathematics (X1, Y2), chemistry (CO2, H2SO4), and scientific notation. Here, we'll explore both HTML and JavaScript methods to create subscripts. Using HTML Tag The simplest way to create subscripts is using the HTML tag. Any text inside this tag will be displayed as a subscript. Syntax Water is H2O ...
Read More