Object Oriented Programming Articles

Page 81 of 589

How to Title Case a sentence in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 10K+ Views

Title case formatting converts the first letter of each word in a sentence to uppercase while keeping the remaining letters lowercase. This is commonly used for headings, titles, and proper formatting of text. Algorithm Split the sentence into individual words using string.split() method Convert all letters in each word to lowercase using string.toLowerCase() method Loop through each word and capitalize the first letter using toUpperCase() Concatenate the capitalized first letter with the remaining lowercase letters Join all words ...

Read More

Write a palindrome program in JavaScript so that only alphanumeric values should be allowed?

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 993 Views

A palindrome is a string that reads the same forwards and backwards. When checking palindromes with alphanumeric characters only, we need to ignore spaces, punctuation, and special characters, considering only letters (a-z) and digits (0-9). For example, "A man, a plan, a canal: Panama" becomes "amanaplanacanalpanama" after removing non-alphanumeric characters, which is indeed a palindrome. Basic Palindrome Check Here's a simple approach using string manipulation methods to check if a string is a palindrome: var str = "racecar"; ...

Read More

How to prevent modification of object in JavaScript ?.

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 480 Views

JavaScript provides three methods to prevent modification of objects at different levels of restriction. These protective measures ensure that objects cannot be accidentally or intentionally altered, maintaining code integrity and predictable behavior. Three Levels of Object Protection 1) Prevent Extensions Object.preventExtensions() prevents new properties from being added to an object, but existing properties can still be modified or deleted. Example var object1 = { prop1: 1 }; Object.preventExtensions(object1); delete ...

Read More

What is non-enumerable property in JavaScript and how can it be created?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

Objects can have properties that don't show up when iterated through the particular object using Object.keys() or for...in loop. Those type of properties are called as non-enumerable properties. What are Non-enumerable Properties? Non-enumerable properties are object properties that are hidden from enumeration methods like Object.keys(), for...in loops, and Object.entries(). However, they can still be accessed directly using their property name. Creating Non-enumerable Properties To create a non-enumerable property we have to use Object.defineProperty() method. This is a special method to create non-enumerable properties in an object. Syntax Object.defineProperty(object, propertyName, { ...

Read More

Describe pass by value and pass by reference in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

JavaScript passes data to functions in two ways: pass by value for primitives (numbers, strings, booleans) and pass by reference for objects and arrays. Understanding this distinction is crucial for avoiding unexpected behavior in your code. Pass by Value In pass by value, a function receives a copy of the variable's value. Changing this copy inside the function doesn't affect the original variable. JavaScript primitives (numbers, strings, booleans, null, undefined) are always passed by value. Example let a = 1; let change = (val) ...

Read More

What is function chaining in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 4K+ Views

Function chaining is a technique that allows you to call multiple methods on the same object in sequence using dot notation. This makes code more concise and improves readability by eliminating the need to repeatedly reference the same object. How Function Chaining Works For function chaining to work, each method must return the object itself (typically using return this). This allows the next method in the chain to be called on the returned object. Without Function Chaining In this example, the methods don't return this, so chaining is not possible: ...

Read More

How to get a part of string after a specified character in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 16K+ Views

To get a part of a string after a specified character in JavaScript, you can use the substring() method combined with indexOf(). This technique allows you to extract portions of text before or after any character. Understanding substring() The substring() method extracts characters from a string between two specified indices. It takes a start index (inclusive) and an optional end index (exclusive). Syntax for Getting Text After a Character string.substring(string.indexOf(character) + 1); Here, indexOf(character) finds the position of the character, and adding + 1 starts extraction from the next position. Syntax for ...

Read More

How to add a number and a string in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 11K+ Views

In JavaScript, when you use the + operator with a number and a string, JavaScript performs concatenation instead of mathematical addition. This is because the presence of a string changes the operation from addition to string concatenation. How It Works JavaScript follows these rules when using the + operator: Number + Number: Mathematical addition String + Number: String concatenation (number is converted to string) Number + String: String concatenation (number is converted to string) Example var a = 5 + 5; ...

Read More

What is the main difference between objects created using object literal and constructor function?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

The main difference between objects created using object literal and constructor function lies in how they handle references and instances. Objects created with object literals are referenced by variables, while constructor functions create independent instances. Let's explore both approaches with examples to understand this fundamental difference. Objects Created Using Object Literal When you create an object using object literal syntax and assign it to multiple variables, all variables point to the same object in memory. This means any change made through one variable affects all other variables referencing that object. Example ...

Read More

What is global namespace pollution in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

Global namespace pollution occurs when too many variables and functions are declared in the global scope, leading to name collisions. This is especially problematic in large projects using multiple JavaScript libraries. What is Name Collision? Name collision happens when two or more scripts define variables or functions with the same name in the global scope. The last definition overwrites previous ones, causing unexpected behavior. Example: Two Teams, Same Function Name Let's demonstrate with two JavaScript files from different teams: TeamA1.js Team A1 creates a student constructor with 2 parameters: function student(fname, lname) ...

Read More
Showing 801–810 of 5,881 articles
« Prev 1 79 80 81 82 83 589 Next »
Advertisements