Front End Technology Articles - Page 518 of 860

w vs W in JavaScript regex?

Lokesh Yadav
Updated on 09-Dec-2022 10:13:21

4K+ Views

This article discusses about the \w vs \W in JavaScript regex. The \w and \W meta characters are used to match the characters of a given string. \w and \W are different from each other. \w (character) is equivalent to [a-zA-Z0-9_] that means it matches any single letter, number, or underscore. The characters that are not matched by the \w are matched by the \W. \W is equivalent to [^a-zA-Z0-9_] that means it matches any character other than letter, number and underscore. To match a string with a pattern, the possible methods are: string.match(pattern), string.search(pattern), pattern.exec(string), pattern.test(text). We use match ... Read More

Why is using “for…in” loop in JavaScript array iteration a bad idea?

Manisha Patil
Updated on 24-Aug-2022 12:51:25

260 Views

The ability to execute a collection of instructions or functions repeatedly while a certain condition holds true is known as looping in programming languages. The for-in statement is used to iterate through the properties of an object. This sentence will move up the prototype chain and display all inherited properties, which is usually undesirable. When it comes to iterating through array elements, there are few reasons why you shouldn't use for..in: For example, if someone changes Array.prototype, which is absolutely bad practise in code that is meant to operate well with the other scripts, for..in will cycle over all ... Read More

How to access a JavaScript object using its own prototype?

vineeth.mariserla
Updated on 26-Aug-2019 08:52:59

405 Views

We can able to access the existing object by creating its own prototype using a javascript method called "Object.create()". Using this method we can inherit the properties from the existing properties to the newly created prototype. Let's discuss it in a nutshell.syntaxObject.create(existing obj);This method takes the existing object and creates its own prototype so that the properties will be inherited from the existing object to the newly created prototype.ExampleIn the following example, Initially, an object named "person" is created and the using "Object.create" its own prototype is created and assigned to a variable "newper". Later on, using the prototype the ... Read More

How to convert a string into integer in JavaScript?

Lokesh Yadav
Updated on 20-Sep-2024 13:21:50

212K+ Views

To convert a string into integer in JavaScript, is a simple task and can be converted using various approaches. Converting string to integer is useful for performing accurate mathematical operations, comparisons and validating user input. We will be discussing various approaches in this article to convert a string into integer in JavaScript In this article, we are having a string value, our task is to convert string to integer in JavaScript. Approaches to Convert String to Integer in JavaScript Here is a list of approaches to convert string to integer in JavaScript which we will be discussing in this ... Read More

JavaScript's Boolean function?

vineeth.mariserla
Updated on 23-Aug-2019 15:17:10

190 Views

Boolean functionWhile developing, a developer may come across yes/no situation. At that point of time Boolean() function can be used. It results only in true or false. Let's discuss it in detail.syntaxBoolean(exp);It takes an expression and scrutinizes it and displays either true or false based on the validity of the expression.Example-1In the following example, various values have been checked whether they are true or not using Boolean() function. If any value has any legitimate value then it results in true else it results in false.  var a = 0;           ... Read More

How to generate a random number in JavaScript?

Manisha Patil
Updated on 23-Aug-2022 14:40:22

2K+ Views

The Math object, a built-in object with attributes or methods for carrying out mathematical operations, has the native implementation of the random() method in JavaScript. As its name suggests, the random() method aids in the generation of random numbers. The return value of the Math.random() method is a floating-point, sort of semi number between 0 (inclusive) and 1. (exclusive). This is defined mathematically by the equation 0 = x 1. The Math.random() function will return a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0 but not 1) with an essentially uniform distribution throughout that ... Read More

Super keyword in JavaScript?

Lokesh Yadav
Updated on 09-Dec-2022 10:09:56

1K+ Views

In this article, we are going to discuss about the super keyword in JavaScript with suitable examples. The Super keyword is basically used in Object Oriented Programming. The Super keyword is used to call parameters and functions of an object’s parent. There are times a parent class and sub class can have same method names and parameter names. In those case, to avoid confusion between the parent class and sub class method names or parameter names, super keyword is used. In order to use a Super keyword, the child method must extend the parent class method. Syntax The syntax to ... Read More

JavaScript Sleep() function?

vineeth.mariserla
Updated on 02-Sep-2023 12:26:06

53K+ Views

Sleep()With the help of sleep() we can make a function to pause execution for a fixed amount of time. In programming languages such as C and PHP we would call sleep(sec). Java has thread.sleep(), Python has time.sleep() and Go has time.Sleep(2 * time.Second).JavaScript doesn't have these kinds of sleep functions. But we should thank promises and async/await function in ES 2018. Because these features have helped us to use sleep() as easy as possible. Let's discuss it in a nutshell.syntax-1sleep(Time in ms).then(() => { //// code })We can use the sleep function with then call back as shown above.syntax-2const work = async () => { await sleep(Time in ... Read More

HTML DOM Input Reset form property

AmitDiwan
Updated on 22-Aug-2019 12:59:34

255 Views

The HTML DOM Input Reset form property is used for returning the form reference that contains the given reset button. If the reset button is outside the form then it will simply return NULL. This property is read-only.SyntaxFollowing is the syntax for input Reset form property.resetObject.formExampleLet us look at an example for the Input Reset form property − Live Demo Input reset form Property UserName: Location: Get the form id by clicking on the below button GET FORM    function formId() {       var P=document.getElementById("RESET1").form.id;       ... Read More

HTML DOM Input Reset disabled property

AmitDiwan
Updated on 22-Aug-2019 12:55:57

242 Views

The HTML DOM Input reset disabled property is used for setting or returning if the reset button should be disabled or not. It uses boolean values, with true representing the reset button should be disabled and false otherwise. The disabled property is set to false by default. The disabled element is greyed out by default and is unclickable.SyntaxFollowing is the syntax for −Setting the disabled property −resetObject.autofocus = true|falseHere, true=reset button is disabled and false=the reset button is not disabled. It is false by default.ExampleLet us look at an example for the Input reset disabled property − Live Demo ... Read More

Advertisements