Javascript Articles

Page 337 of 534

How to set fontStyle, fontVariant, fontWeight, fontSize, lineHeight, and fontFamily in one declaration with JavaScript?

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 157 Views

To set all the font properties in a single declaration, use the JavaScript font property. This shorthand property combines fontStyle, fontVariant, fontWeight, fontSize, lineHeight, and fontFamily into one statement. Syntax element.style.font = "fontStyle fontVariant fontWeight fontSize/lineHeight fontFamily"; Font Property Components The font property accepts values in a specific order: fontStyle: normal | italic | oblique fontVariant: normal | small-caps fontWeight: normal | bold | lighter | bolder | 100-900 fontSize: Required value (px, em, %, etc.) lineHeight: Optional, follows fontSize with "/" separator fontFamily: Required font name(s) Example ...

Read More

How to turn words into whole numbers JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

We need to write a function that takes a string of number words as input and converts them into their equivalent whole number. Problem Overview Given a string containing number words separated by spaces, we want to convert each word to its corresponding digit and combine them into a single number. "one five seven eight" -------> 1578 "two eight eight eight" -------> 2888 Approach The solution involves creating a mapping of number words to digits, then iterating through each word to build the final number. We split the input string by whitespace ...

Read More

How to set the width of the rule between columns with JavaScript?

Monica Mona
Monica Mona
Updated on 15-Mar-2026 156 Views

The columnRuleWidth property controls the thickness of the vertical line that appears between columns in a multi-column layout. This property works with CSS multi-column layouts created using column-count or column-width. Syntax element.style.columnRuleWidth = "value"; The value can be specified in pixels (px), ems, or keywords like thin, medium, or thick. Example #myID { column-count: 4; column-rule: 4px solid yellow; ...

Read More

JavaScript program to take in a binary number as a string and returns its numerical equivalent in base 10

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 315 Views

We are required to write a JavaScript function that takes in a binary number as a string and returns its numerical equivalent in base 10. Therefore, let's write the code for the function. This one is quite simple, we iterate over the string using a for loop and for each passing bit, we double the number with adding the current bit value to it like this − Example const binaryToDecimal = binaryStr => { let num = 0; for(let i = 0; i < binaryStr.length; i++){ ...

Read More

How to set column width and column count with JavaScript?

Vikyath Ram
Vikyath Ram
Updated on 15-Mar-2026 811 Views

To set the column width and column count in a single declaration, use the JavaScript columns property. This CSS property is a shorthand that combines column-width and column-count into one convenient declaration. Syntax element.style.columns = "width count"; // or element.style.columns = "width"; element.style.columns = "count"; Parameters width - Minimum width of each column (e.g., "100px", "10em") count - Number of columns (e.g., 2, 3, 4) Example The following example demonstrates how to change column layout dynamically using JavaScript: ...

Read More

JavaScript Compare two sentences word by word and return if they are substring of each other

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 221 Views

The idea here is to take two strings as input and return true if one string is a substring of the other, otherwise return false. For example: isSubstr('hello', 'hello world') // true isSubstr('can I use', 'I us') // true isSubstr('can', 'no we are') // false In the function, we check which string is longer and then verify if the shorter string exists as a substring within the longer one. Syntax const isSubstr = (first, second) => { if (first.length > second.length) { ...

Read More

Set how many columns an element should span across with JavaScript.

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 426 Views

In this tutorial, we will learn to set how many columns an element should span across with JavaScript. Dividing long paragraphs or articles into many columns improves their readability. The 'column-count' CSS property divides the text into numerous columns. Set the columnSpan property to all if you want the columns to span across in JavaScript. To set how many columns an element should span across with JavaScript, we have multiple ways, and in this tutorial, we will discuss two of them − Set the columnSpan property Use the style.setProperty method ...

Read More

Difference between window.location.href, window.location.replace and window.location.assign in JavaScript?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 765 Views

The window object includes the location object in JavaScript, which provides three different methods for navigating between pages. Each method has distinct behavior regarding browser history and navigation. window.location.href The href property gets or sets the complete URL of the current page. When assigned a new value, it navigates to that URL and adds an entry to the browser's history stack. Example Click below to get the complete URL of the page. Get Current URL ...

Read More

How to selectively retrieve value from json output JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 266 Views

We have the following data inside a JSON file data.json: data.json { "names": [{ "name": "Ramesh", "readable": true }, { "name": "Suresh", "readable": false }, { "name": "Mahesh", "readable": true }, { "name": "Gourav", "readable": true }, { "name": "Mike", "readable": false }] } ...

Read More

Which is the best JavaScript compressor?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 270 Views

JavaScript compressors reduce file sizes by removing unnecessary whitespace, comments, and optimizing code structure. Here are the best options available for different needs. Google Closure Compiler Google Closure Compiler is one of the most powerful JavaScript optimization tools. It parses JavaScript, analyzes it, removes dead code, rewrites inefficient patterns, and minimizes the output. Unlike simple minifiers, it performs advanced optimizations like function inlining and variable renaming. Original JS function add(a, b){ return a + b; ...

Read More
Showing 3361–3370 of 5,340 articles
« Prev 1 335 336 337 338 339 534 Next »
Advertisements