Manisha Patil

Manisha Patil

32 Articles Published

Articles by Manisha Patil

Page 3 of 4

How to generate a random number in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 2K+ Views

JavaScript's Math.random() method is the built-in way to generate random numbers. It returns a floating-point number between 0 (inclusive) and 1 (exclusive), which can be scaled to any desired range. The Math.random() function returns a pseudo-random number in the range [0, 1) with uniform distribution. The implementation generates the seed automatically, and users cannot modify it. Basic Math.random() Usage Syntax Math.random() Return Value A floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). Example Random Number Generation ...

Read More

"extends" keyword in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 1K+ Views

In JavaScript, the extends keyword enables class inheritance, allowing you to create child classes that inherit properties and methods from parent classes. This is a fundamental feature of ES6 classes that promotes code reusability and establishes clear hierarchical relationships between classes. Class inheritance allows you to build upon existing functionality without rewriting code. The child class automatically gains access to all public methods and properties of its parent class, while still being able to add its own unique features or override inherited behavior. Syntax class ChildClass extends ParentClass { // Child class ...

Read More

How to get the protocol and page path of the current web page in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 784 Views

In JavaScript, you can retrieve both the protocol (like https:// or http://) and the page path of the current webpage using the window.location object and URL constructor. These properties are essential for web development tasks like URL manipulation and navigation. Getting the Protocol The protocol specifies the data transfer method used by the URL. Use window.location.protocol or URL.protocol to retrieve it. Syntax protocol = window.location.protocol; // or protocol = new URL(url).protocol; Using window.location.protocol Protocol Example ...

Read More

Why is using "for...in" loop in JavaScript array iteration a bad idea?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 307 Views

The for...in loop in JavaScript is designed for iterating over object properties, not array elements. Using it for arrays can lead to unexpected behavior and performance issues. Main Problems with for...in on Arrays There are several critical issues when using for...in loops with arrays: Prototype pollution: If Array.prototype is modified, for...in will iterate over inherited properties, not just array elements. No guaranteed order: for...in doesn't guarantee that array elements will be processed in numerical order. Performance overhead: The loop checks the entire prototype chain, making it slower ...

Read More

What is the importance of '/g' flag in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 661 Views

The /g flag in JavaScript regular expressions stands for "global" and is essential for finding all matches in a string rather than stopping after the first match. Without this flag, regex methods will only find the first occurrence of a pattern. Understanding Regular Expressions Regular expressions are patterns used to match character combinations in strings. They can be created in two ways: Literal notation: Uses forward slashes with optional flags after the second slash (e.g., /pattern/g). This is preferred when the pattern remains constant. Constructor function: Uses new RegExp("pattern", "flags"). This is useful when the pattern ...

Read More

What is the importance of '/i' flag in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 541 Views

The /i flag in JavaScript is a regular expression modifier that enables case-insensitive pattern matching. By default, regular expressions are case-sensitive, meaning they distinguish between uppercase and lowercase letters. Understanding Regular Expressions Regular expressions are patterns used to match character combinations in strings. They can be created using two methods: Literal notation: Uses slashes to enclose the pattern (/pattern/flags). Best for static patterns that won't change during execution. Constructor method: Uses the RegExp constructor (new RegExp("pattern", "flags")). Ideal when the pattern needs to be dynamic or constructed at runtime. ...

Read More

How to find the href and target attributes in a link in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 7K+ Views

In JavaScript, you can access and manipulate the href and target attributes of anchor elements using DOM methods. These attributes control where links point and how they open. Finding href and target Attributes You can retrieve these attributes using getAttribute() or directly access them as properties of the anchor element. Finding href and target attributes TutorialsPoint let link = document.getElementById('myLink'); ...

Read More

Tag names of body element's children in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 500 Views

In JavaScript, you can access the tag names of child elements within the body using the children property or the querySelector method. The children property returns an HTMLCollection of all child elements, while querySelector allows you to target specific elements using CSS selectors. Using the children property to get all child elements Using the querySelector method to select specific child elements Both approaches provide different ways to access and manipulate child elements within the DOM structure. Using the children Property The DOM children property returns an HTMLCollection of all child ...

Read More

Is JavaScript a pass-by-reference or pass-by-value language?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 599 Views

JavaScript provides functions that contain a collection of instructions executed when called. These functions can accept arguments as input, and understanding how JavaScript passes these arguments is crucial for effective programming. JavaScript uses pass by value for all function parameters. This means JavaScript creates copies of variable values when passing them to functions. However, the behavior differs between primitive types and objects due to how JavaScript handles references. Pass By Value (Primitives) For primitive data types (numbers, strings, booleans), JavaScript creates a complete copy of the value. Changes inside the function don't affect the original variable. ...

Read More

What is JavaScript's highest integer value that a Number can go to without losing precision?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 23K+ Views

JavaScript's highest integer value that maintains precision is Number.MAX_SAFE_INTEGER, which equals 9, 007, 199, 254, 740, 991 (253 - 1). This limitation exists because JavaScript uses IEEE 754 double-precision floating-point format for numbers. Understanding Safe Integer Range JavaScript can only properly represent integers between -(253 - 1) and 253 - 1. The term "safe" means you can accurately represent, compare, and perform arithmetic operations on integers within this range. ...

Read More
Showing 21–30 of 32 articles
Advertisements