Lokesh Yadav

Lokesh Yadav

38 Articles Published

Articles by Lokesh Yadav

Page 2 of 4

Built-in javascript constructors?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 1K+ Views

In this article, we are going to discuss about the Built-in JavaScript constructors with appropriate examples in JavaScript. JavaScript has provided some built-in constructors for native objects. These built-in functions include Object(), String(), Boolean(), RegExp(), Number(), Array(), Function(), and Date(). Note: We cannot include the Math object in those built-in constructors because Math is a global object. The new keyword cannot be used with Math. Let's understand this concept in a better way with the help of examples further in this article. String() Constructor The String() constructor converts values to strings. Here's an example demonstrating ...

Read More

How to find the inner height and inner width of a browser window in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 688 Views

In this article we are going to learn how to find the inner height and inner width of a browser window using JavaScript. JavaScript defines window object methods and properties. The properties include inner height and inner width, which helps us to calculate the height and width of a window's content area excluding scrollbars, toolbars, and other browser UI elements. There are two main approaches to calculate the inner height and inner width of a window: Using innerHeight and innerWidth properties − The window.innerHeight and window.innerWidth properties return the viewport dimensions including padding ...

Read More

w vs W in JavaScript regex?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 4K+ Views

In JavaScript regex, \w and \W are complementary metacharacters used to match different types of characters. \w matches word characters (letters, digits, and underscores), while \W matches non-word characters (everything else). Understanding \w Metacharacter The \w metacharacter is equivalent to [a-zA-Z0-9_], matching any single letter (uppercase or lowercase), digit, or underscore. Syntax // Using RegExp constructor RegExp("\w", "g") // Using literal notation /\w/g Example: Using \w to Match Word Characters \w vs \W in JavaScript regex \w Metacharacter Example ...

Read More

d vs D in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 3K+ Views

In JavaScript regular expressions, \d and \D are metacharacters used to match different types of characters in strings. Understanding their differences is essential for effective pattern matching. \d matches any single digit character (equivalent to [0-9]), while \D matches any character that is NOT a digit (equivalent to [^0-9]). These metacharacters are complete opposites of each other. Syntax Both metacharacters can be used in two ways: // Using RegExp constructor new RegExp("\d", "g") // matches digits new RegExp("\D", "g") // matches non-digits // Using regex literal /\d/g ...

Read More

How to know the browser language and browser platform in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 765 Views

In this article we are going to discuss how to know the browser language and browser platform with the help of examples in JavaScript To know the various properties of the browser, JavaScript provides the Navigator object. The Navigator object has several properties, which include - connection, credentials, cookies, geolocation, language, platform, etc. We are concerned with Navigator.language and Navigator.platform to know the language and platform of the browser. Let us discuss about them in detail. Navigator.language The read-only Navigator.language property returns a string that represents the browser UI language. It returns a string that contains the ...

Read More

How to add a new element to HTML DOM in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 74K+ Views

In JavaScript, adding new elements to the HTML DOM involves creating elements and inserting them into the document structure. This process requires understanding three key methods: createElement(), createTextNode(), and appendChild(). Core Methods for DOM Manipulation The Document object provides essential methods for creating and adding elements to the DOM: document.createElement(tagName) - Creates a new HTML element document.createTextNode(text) - Creates a text node appendChild(element) - Adds an element as the last child insertBefore(newElement, referenceElement) - Inserts an element before a reference element Syntax // Create element const element = document.createElement(tagName); // Create ...

Read More

Weekday as a number in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 4K+ Views

In JavaScript, the getDay() method from the Date object returns the weekday as a number from 0 to 6, where Sunday is 0, Monday is 1, and so on. Syntax dateObject.getDay() The method returns an integer representing the day of the week: 0 = Sunday 1 = Monday 2 = Tuesday 3 = Wednesday 4 = Thursday 5 = Friday 6 = Saturday Example 1: Current Date Weekday Get the ...

Read More

Retrieve element from local storage in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 7K+ Views

To retrieve elements from local storage in JavaScript, we use the localStorage.getItem() method. Local storage provides persistent client-side data storage that remains available even after closing the browser. Local storage is a web API that allows you to store key-value pairs in a user's browser. Unlike session storage, data in local storage persists until explicitly removed or cleared by the user. This makes it ideal for storing user preferences, application state, or cached data. Local Storage Methods Local storage provides four main methods for data management: setItem(key, value) - Stores a key-value ...

Read More

How to remove existing HTML elements in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 47K+ Views

This article discusses how to delete existing HTML elements in JavaScript. To remove HTML elements, you first need to select the element from the document, then use methods like remove() and removeChild() to delete them from the DOM. Using the remove() Method The remove() method directly removes an element from the DOM. It's the simplest approach for modern browsers. Syntax element.remove(); Example Remove Element Example This heading will be removed This paragraph will remain ...

Read More

How to get a particular anchor in a document in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 2K+ Views

In this article we will learn how to get a particular anchor in a document in JavaScript. JavaScript provides multiple ways to access anchor elements ( tags) in a document. Anchor elements follow an array-like structure, allowing you to select specific anchors by index or use DOM methods to retrieve them. There are two primary methods to get a particular anchor element: using document.anchors collection or document.getElementsByTagName("a") method. Syntax The syntax to get a particular anchor tag is shown below: // Method 1: Using document.anchors collection document.anchors[index].innerHTML // Method 2: Using getElementsByTagName document.getElementsByTagName("a")[index].innerHTML ...

Read More
Showing 11–20 of 38 articles
Advertisements