vineeth.mariserla

vineeth.mariserla

72 Articles Published

Articles by vineeth.mariserla

Page 7 of 8

How to access 'this' keyword inside an arrow function in JavaScript?

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

The JavaScript 'this' keyword refers to the object it belongs to. Arrow functions handle 'this' differently than regular functions - they inherit 'this' from their surrounding scope rather than creating their own. How Arrow Functions Handle 'this' Arrow functions don't have their own 'this' binding. Instead, they capture the 'this' value from the enclosing lexical scope at the time they are defined. function Student(fname, grade) { this.fname = fname; this.grade = grade; this.details = function() { ...

Read More

JavaScript Sleep() function?

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

JavaScript doesn't have a built-in sleep() function like other languages (C's sleep(), Java's Thread.sleep(), Python's time.sleep()). However, we can create one using Promises and async/await. Creating a Sleep Function We can implement a sleep function using setTimeout() wrapped in a Promise: function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } Using Sleep with Promises function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } console.log("Start"); sleep(2000).then(() => { console.log("After 2 seconds"); }); Start ...

Read More

How to concatenate two strings so that the second string must concatenate at the end of first string in JavaScript?

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

String concatenation is the process of joining two or more strings together to create a new string. In JavaScript, there are several methods to concatenate strings, with the second string being appended at the end of the first string. Using concat() Method The concat() method joins the calling string with the provided string arguments to create a new string. The original strings remain unchanged since strings in JavaScript are immutable. Syntax concat(str1) concat(str1, str2) concat(str1, str2, ... , strN) Parameters Parameter Description strN One or more strings to ...

Read More

How to access a function property as a method in JavaScript?

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

In JavaScript, object properties can hold functions, which become methods when accessed through the object. A method is simply a function that belongs to an object and can access the object's other properties using the this keyword. Syntax const object = { property1: value1, property2: value2, methodName: function() { return this.property1 + this.property2; } }; // Call the method object.methodName(); Example 1: Employee Object with fullName Method Here's an ...

Read More

How to hide e-mail address from an unauthorized user in JavaScript?

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

Hiding email addresses from unauthorized users helps protect privacy and reduce spam. JavaScript provides several methods to obfuscate email addresses while keeping them readable for legitimate users. Method 1: Partial Masking with Asterisks This approach replaces part of the username with asterisks, keeping the domain visible: function hideEmail(email) { var parts = email.split("@"); var username = parts[0]; var domain = parts[1]; if (username.length 2 ? ...

Read More

How to get the length of an object in JavaScript?

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

In JavaScript, objects don't have a built-in length property like arrays and strings. When you try to access object.length, it returns undefined. To get the number of properties in an object, you need to use specific methods. Why Objects Don't Have a Length Property The length property only works for arrays and strings, not plain objects: var object = {prop1: 1, prop2: 2}; document.write("Object length: " + object.length); Object length: undefined Arrays and Strings Have Length For comparison, ...

Read More

What is the importance of str.padStart() method in JavaScript?

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

The padStart() method in JavaScript pads a string at the beginning to reach a specified length. It's particularly useful for formatting numbers, creating aligned text, and adding prefixes with consistent string lengths. Syntax string.padStart(targetLength, padString) Parameters targetLength: The desired length of the resulting string after padding. padString (optional): The string to use for padding. Defaults to a space character if not provided. Return Value Returns a new string padded at the beginning. The original string remains unchanged. Basic Example ...

Read More

What is the importance of "enumerable" attribute in defining a property in JavaScript object?

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

The enumerable attribute controls whether a property appears in object enumeration methods like for...in loops, Object.keys(), and JSON.stringify(). When using Object.defineProperty(), properties are non-enumerable by default. Syntax Object.defineProperty(objectName, propertyName, { value: propertyValue, enumerable: true/false }) Default Behavior: Non-enumerable Property When enumerable is not specified, it defaults to false, making the property invisible to enumeration methods: var object = {one: 1}; Object.defineProperty( object, ...

Read More

How to remove non-word characters in JavaScript?

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

To remove non-word characters in JavaScript, we use regular expressions to replace unwanted characters with empty strings. Non-word characters include symbols, punctuation, and special characters that aren't letters, numbers, or underscores. What are Non-Word Characters? Non-word characters are anything that doesn't match the \w pattern in regex. This includes symbols like !@#$%^&*(), punctuation, and special characters, but excludes letters (a-z, A-Z), digits (0-9), and underscores (_). Using Simple Regex Pattern The most straightforward approach uses the \W pattern, which matches any non-word character: function removeNonWordChars(str) { if ...

Read More

How to decode an encoded string in JavaScript?

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

In JavaScript, string decoding refers to converting encoded strings back to their original form. While escape() and unescape() were historically used, modern JavaScript provides better alternatives like decodeURIComponent() and decodeURI(). Using unescape() (Deprecated) The unescape() method decodes strings encoded by the escape() method. It replaces hexadecimal escape sequences with their corresponding characters. Syntax unescape(string) Example // Special character encoded with escape function var str = escape("Tutorialspoint!!"); document.write("Encoded : " + str); document.write(""); ...

Read More
Showing 61–70 of 72 articles
« Prev 1 4 5 6 7 8 Next »
Advertisements