Sravani Alamanda

Sravani Alamanda

15 Articles Published

Articles by Sravani Alamanda

Page 2 of 2

Can I use a JavaScript variable before it is declared?

Sravani Alamanda
Sravani Alamanda
Updated on 08-Dec-2022 3K+ Views

Yes, you can use a JavaScript variable before it is declared, with a technique called hoisting. The parser reads through the complete function before running it. The behavior in which a variable appears to be used before it's declared is known as hoisting. For example, the following, rank = 5; var rank; The above works the same as the following − var rank; rank = 2; Hoisting in JavaScript, allows us to declare variables, functions, or classes that are moved to the top of the scope preceding the execution of the code regardless of whether their scope ...

Read More

Find digits not between the brackets using JavaScript Regular Expressions?

Sravani Alamanda
Sravani Alamanda
Updated on 08-Dec-2022 224 Views

In JavaScript, the regular expression [^0-9] is used to find the characters inside the bracket but not a digit. Except digit mentioned in the bracket, it will return the remaining characters from the text as an array. We all know about RegExp (Regular Expression) in JavaScript. RegExp is an object that specifies the pattern used to do a search and replace operations on the string or for input validation. RegExp was introduced in ES1 and it is fully supported by all browsers. Syntax Syntax for non-digit or /[^0-9]/ character is- new RegExp("[^0-9]") or simply /[^0-9]/ Here /[^0-9]/ , ...

Read More

Are both addition and concatenation same in JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 08-Dec-2022 2K+ Views

We can't say whether both are the same or both are different. In some cases, addition and concatenation will have the same result, but in some cases, they will be different. It is completely based on the type of variables. We will see it in detail below We use the + operator for addition and the concat() method for concatenation in JavaScript. In some cases, both the + operator and the concat() method returns the same result. Adding and concatenating two strings using the + operator and the concat() method returns the same result. We can also apply the ...

Read More

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

Sravani Alamanda
Sravani Alamanda
Updated on 26-Aug-2022 235 Views

No, it is not recommended to use HTML comments to comment blocks of code. When JavaScript has first released some browsers didn’t have any support to understand the script. So a technique was then needed to hide the script code for older browsers. So that time the HTML comment within the JavaScript block was used to prevent the older browsers from showing the script code as text on the page. This technique was followed in the 1990s. Such browsers do not exist now, which wanted you to use HTML comments in JavaScript. Now all browsers understand the JavaScript blocks, so ...

Read More

Find a form feed character with JavaScript RegExp.

Sravani Alamanda
Sravani Alamanda
Updated on 26-Aug-2022 1K+ Views

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

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