Sravani Alamanda

Sravani Alamanda

15 Articles Published

Articles by Sravani Alamanda

15 articles

Calculate text width with JavaScript

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 10K+ Views

To calculate text width, we can use the measureText() method in JavaScript. In canvas, the measureText() method is used to measure width of the text content. This means we can pass text to this canvas method and then call that method to measure the text. It will return an object that contains information about the measured text. Sometimes, width may be a float value; hence the Math.ceil() method is used to round the value and returns an integer. Syntax Following is the syntax of the method used to calculate the text width: const text = ...

Read More

Does it make sense to use HTML comments on blocks of JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 245 Views

No, it does not make sense to use HTML comments on blocks of JavaScript in modern web development. HTML comments within JavaScript were a workaround used in the 1990s to hide JavaScript code from very old browsers that didn't understand the tag. Since all modern browsers support JavaScript, this practice is obsolete and not recommended. Historical Context: Why HTML Comments Were Used In the early days of JavaScript (1995), browsers like Netscape 1 didn't support the tag. Without HTML comments, these browsers would display JavaScript code as plain text on the webpage. The HTML comment syntax ...

Read More

Are both addition and concatenation same in JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 2K+ Views

In JavaScript, addition and concatenation are fundamentally different operations that can produce similar results depending on the data types involved. The + operator performs both operations contextually, while the concat() method is specifically for concatenation. The + operator behaves differently based on operand types: when at least one operand is a string, it performs concatenation; when both operands are numbers, it performs arithmetic addition. The concat() method, however, is only available for strings and arrays. String Operations For strings, both + operator and concat() method produce identical results. Using Addition (+) ...

Read More

How to catch syntax errors in JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn how to catch syntax errors in JavaScript and handle them effectively. JavaScript throws various types of errors when we write incorrect code: ReferenceError when calling undefined variables, TypeError when trying to modify immutable values inappropriately, and SyntaxError when the code structure is invalid. What is Syntax Error? A SyntaxError occurs when JavaScript encounters code that violates the language's syntax rules. Unlike runtime errors, syntax errors are detected during the parsing phase, before the code executes. Common Causes of Syntax Errors Missing brackets: Unclosed parentheses (), braces ...

Read More

How to catch any JavaScript exception in Clojurescript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 282 Views

ClojureScript is a dialect of the Clojure programming language that compiles to JavaScript, allowing developers to use Clojure's functional programming paradigms in web browsers and Node.js environments. When building ClojureScript applications, proper exception handling is crucial for maintaining application stability and user experience. What is ClojureScript? ClojureScript is a compiler that transforms Clojure code into optimized JavaScript. Originally, Clojure only compiled to Java Virtual Machine bytecode, but ClojureScript emerged in 2011 to bring Clojure's powerful features to client-side development. ClojureScript operates at a higher abstraction level than JavaScript. While JavaScript deals with variables, loops, conditions, and objects, ...

Read More

How -Infinity is converted to String in JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 365 Views

In JavaScript, -Infinity is a special numeric value that represents negative infinity. When we need to convert it to a string, we can use the String() method or the toString() method. The -Infinity value typically results from mathematical operations like dividing a negative number by zero or when a calculation exceeds the minimum representable number in JavaScript. Syntax The String() method converts any JavaScript value to a string representation: String(value) Where value is any JavaScript value. The method returns the string representation of that value. Using String() Method The most reliable ...

Read More

Find digits not between the brackets using JavaScript Regular Expressions?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 241 Views

In JavaScript, regular expressions with negated character classes [^0-9] are used to find characters that are NOT digits. The caret ^ inside square brackets creates a negated character class, matching any character except those specified. Regular expressions (RegExp) are powerful pattern-matching tools introduced in ES1 and supported by all modern browsers. They're commonly used for string validation, search operations, and text manipulation. Syntax The syntax for matching non-digits is: new RegExp("[^0-9]") // or simply /[^0-9]/ With modifiers for global matching: new RegExp("[^0-9]", "g") // or simply /[^0-9]/g ...

Read More

Find the non-digit character with JavaScript Regular Expression

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn to find non-digit characters using JavaScript regular expressions. The \D metacharacter matches any character that is not a digit (0-9), including letters, spaces, and special characters. RegExp is an object that specifies patterns used for search and replace operations on strings or input validation. RegExp was introduced in ES1 and is fully supported by all browsers. Syntax The syntax for matching non-digit characters is: new RegExp("\D") // Constructor syntax /\D/ // Literal syntax (recommended) ...

Read More

Find a form feed character with JavaScript RegExp.

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 1K+ Views

Form feed character is a page breaking ASCII control character commonly used for page separators. When you want to insert a page break, text editors can use this form feed. It is defined as \f and has an ASCII code value of 12 or 0x0c. RegExp is an object that specifies the pattern used to perform search and replace operations on strings or for input validation. RegExp was introduced in ES1 and is fully supported by all browsers. Now, we will check how to find the form feed (\f) character in given text using RegExp. Syntax ...

Read More

Can I use a JavaScript variable before it is declared?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 3K+ Views

Yes, you can use a JavaScript variable before it is declared due to a mechanism called hoisting. However, the behavior differs significantly between var, let, and const. What is Hoisting? Hoisting is JavaScript's behavior where variable and function declarations are moved to the top of their scope during compilation. This means the JavaScript engine "sees" declarations before the code executes, but only declarations are hoisted—not initializations. Hoisting with var Variables declared with var are hoisted and initialized with undefined: var Hoisting Example ...

Read More
Showing 1–10 of 15 articles
« Prev 1 2 Next »
Advertisements