Web Development Articles

Page 433 of 801

Window innerWidth and innerHeight Properties in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 250 Views

The window.innerWidth and window.innerHeight properties return the width and height of the browser window's content area, excluding toolbars, scrollbars, and borders. Syntax let width = window.innerWidth; let height = window.innerHeight; Properties innerWidth - Returns the interior width of the window in pixels innerHeight - Returns the interior height of the window in pixels Both properties are read-only and return integer values Values change when the browser window is resized Example Window Dimensions ...

Read More

Highlight a text, every time page loads with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 357 Views

To highlight text every time a page loads in JavaScript, you can use a for loop to iterate through words and wrap specific words in elements with CSS classes for styling. Approach The technique involves: Getting the text content using getElementById() Splitting the text into an array of words using split(" ") Looping through each word to find matches Wrapping matching words with tags Rejoining the array and updating the HTML content Example Text ...

Read More

How to invoke a function as a function and method?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 174 Views

In JavaScript, functions can be invoked in different ways. When called directly, it's function invocation. When called as a property of an object, it's method invocation. Function vs Method Invocation Function invocation: Calling a function directly by its name. Method invocation: Calling a function that belongs to an object using dot notation. Example Function and Method Invocation body { ...

Read More

Extract the value of the to a variable using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 799 Views

To extract the value of the element to a variable using JavaScript, use the textContent property to get the text content from any HTML or SVG text element. Syntax var textValue = document.getElementById("elementId").textContent; Example Extract SVG Text Value This is the JavaScript Tutorial ...

Read More

Block Scoping in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 358 Views

Block scope is an area between two curly braces { } which can be between loops, if conditions, or switch statements. The let and const keywords introduced in ES2015 allow us to create block-scoped variables that can only be accessed within that specific block. Understanding Block Scope Variables declared with let and const have block scope, meaning they exist only within the nearest enclosing block. This is different from var, which has function scope. Example: Block Scope with let Block Scoping Example ...

Read More

How can we separate the special characters in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 368 Views

In JavaScript, you can separate special characters from text using the match() method with regular expressions. This technique splits strings into arrays containing both word characters and special characters as separate elements. Syntax arrayName.flatMap(item => item.match(/\w+|\W+/g)); The regular expression /\w+|\W+/g works as follows: \w+ matches one or more word characters (letters, digits, underscore) | acts as OR operator \W+ matches one or more non-word characters (special characters, spaces) g flag ensures global matching throughout the string Example: Separating Special Characters from Names Let's separate special characters from an array of ...

Read More

Explain JavaScript Error Object.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 370 Views

The Error object is thrown by the JavaScript interpreter when a script error occurs. It can also be used to create custom exceptions. Understanding Error objects helps in debugging and error handling in JavaScript applications. Error Object Properties Property Description name Sets or returns the name/type of the error message Sets or returns the error message as a string Example: Catching and Displaying Error Properties JavaScript Error Object body { ...

Read More

How can I cut a string after X characters in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 756 Views

To cut a string after X characters in JavaScript, you can use several methods. The most common approaches are substr(), substring(), and slice(). Using substr() Method The substr() method extracts a portion of a string, starting at a specified index and extending for a given number of characters. var myName = "JohnSmithMITUS"; console.log("The String = " + myName); var afterXCharacter = myName.substr(0, 9); console.log("After cutting the characters the string = " + afterXCharacter); The String = JohnSmithMITUS After cutting the characters the string = JohnSmith Using substring() Method The substring() ...

Read More

How to remove elements using the splice() method in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 366 Views

The splice() method is used to remove elements from an array by specifying the starting index and the number of elements to delete. It modifies the original array and returns an array of the removed elements. Syntax array.splice(startIndex, deleteCount) Parameters startIndex: The index at which to start removing elements deleteCount: The number of elements to remove Example: Remove Single Element Splice Method Example Remove Elements using ...

Read More

Avoid Unexpected string concatenation in JavaScript?

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

JavaScript string concatenation can lead to unexpected results when mixing strings and numbers. Using template literals with backticks provides a cleaner, more predictable approach than traditional concatenation methods. The Problem with Traditional Concatenation When using the + operator, JavaScript may perform string concatenation instead of numeric addition: let name = "John"; let age = 25; let score = 10; // Unexpected string concatenation console.log("Age: " + age + score); // "Age: 2510" (not 35!) console.log(name + " is " + age + " years old"); Age: 2510 John is 25 years ...

Read More
Showing 4321–4330 of 8,010 articles
« Prev 1 431 432 433 434 435 801 Next »
Advertisements