Found 6710 Articles for Javascript

How to create conditional types in TypeScript?

Shubham Vora
Updated on 21-Feb-2023 15:45:25

1K+ Views

In TypeScript, we need to define the types for every variable and object as it is a type of strict language and also contains conditional types. From the word conditional type, we can predict that we need to choose a variable based on a particular condition. Yes, you heard right. As we use an if-else statement to execute the particular code block based on a certain condition, we can also choose a type of variable based on a certain condition. In this tutorial, we will learn to create condition types in TypeScript. Syntax Users can follow the syntax below to ... Read More

How to create asynchronous function in TypeScript?

Shubham Vora
Updated on 21-Feb-2023 15:47:51

7K+ Views

Asynchronous programming allows us to perform multiple tasks parallelly. We can use the async/await keyword to make the function asynchronous. Before we start, let’s learn the need for asynchronous programming and function. It takes some time to respond when we fetch data from the API. Now, think we need to use the results in our app, which we get from API. The single-threaded programming language like TypeScript and JavaScript never stops the execution of the code. So, It doesn’t wait for the response of the API and starts performing some operation on null values. When we make the function asynchronous, ... Read More

How to convert string to number in TypeScript?

Shubham Vora
Updated on 21-Feb-2023 15:42:38

28K+ Views

The string and number are both primitive data types in TypeScript. Sometimes, we get the number in the string format, and we need to convert the string values to the number to perform mathematical operations on the value. If we perform the mathematical operation on the string values, it gives weird results. For example, adding another number value to the string of numbers appends the number to the string rather than adding. We will learn to convert strings to numeric values using various methods and approaches in TypeScript. So, we require to convert the string to a number in TypeScript. ... Read More

Find Hypotenuse of a Number In TypeScript

Shubham Vora
Updated on 21-Feb-2023 15:41:05

334 Views

The longest side of a right-angled triangle and the side that faces away from the right angle is known as the Hypotenuse. The Pythagorean theorem explains that the Hypotenuse's square equals the sum of the squares of the other two sides. We can be used to determine it using this theorem. The formula representation for this theorem is c2 = a2 + b2, where c means the Hypotenuse and a and b are the triangle's two sides. When the lengths of the other two sides of a triangle are known, the Pythagorean theorem quickly determines the value of the Hypotenuse. ... Read More

Duck Typing in TypeScript

Shubham Vora
Updated on 21-Feb-2023 15:39:08

1K+ Views

What is Duck Typing? First, we will know what Duck Typing is. According to programmers, the circumstance where an object's type is decided by its behaviour, like methods and attributes, rather than its class is known as "duck typing". Duck Typing in TypeScript The usage of interfaces in TypeScript makes duck typing possible. Where interface means the set of methods and characteristics an object must have to fall under that type are described. For example, if an interface defines the function, any object with the method called "myFunc()" may be treated as belonging to a specific kind, regardless of ... Read More

Conditional Properties Using React with TypeScript

Shubham Vora
Updated on 21-Feb-2023 15:36:11

6K+ Views

In React with TypeScript, you can use conditional rendering to choose what to render based on a condition. This is useful when displaying different content or components based on specific criteria. There are a few different ways to implement conditional rendering in React with TypeScript. One way is to use the conditional operator (also known as the ternary operator). This operator takes a condition and returns one value if the condition is true and another if the condition is false. You can also use the && operator to render a component based on a condition conditionally. This operator evaluates to ... Read More

Access an Element in Type Script

Shubham Vora
Updated on 21-Feb-2023 15:33:50

15K+ Views

In TypeScript, to access an element, or we can say HTML components, we use the Document Object Model (DOM). The DOM defines an HTML and XML programming interface that visualizes a document's structure as a tree of nodes. A paragraph, a button, a div, a heading, etc., are just a few examples of the document elements each node in the tree represents. The document object in TypeScript serves as the doorway to the DOM. This means we can easily access the elements of the DOM using TypeScript. There are several ways to access elements, those are − Using the ... Read More

How to change the value of a global variable inside of a function using JavaScript?

Abhishek
Updated on 17-Feb-2023 11:44:02

4K+ Views

There are two types of variables can be declared in any programming languages in context of their accessing scope. The Local variable and the Global variable. Global Scoped Variables − The global scoped variables are the variables which are declared globally inside the code file and can be accessed by any code block or any function inside the file. The scope of these variables is global. Local Scoped Variables − These are the variable, which declared inside a function or a particular block of code and can only be accessed or used within that particular block of code not outside ... Read More

How to Change the Time Interval of setinterval() Method at RunTime using JavaScript ?

Abhishek
Updated on 17-Feb-2023 11:57:00

3K+ Views

The setInterval() method is used to call a particular block of code again and again after a particular interval of time that is given to it in its round braces as parameter. The setInterval() method accepts two parameters, the first is the code that has to be executed again and again while the second is the time in which the code has to be execute again. In this article, we are going to learn about the methods of changing the time interval of the setInterval() method at the runtime. So that, it will execute the given code at the irregular ... Read More

How to change the text of a label using JavaScript?

Abhishek
Updated on 17-Feb-2023 11:55:49

6K+ Views

Before going to learn about the method of changing the text of a label element in HTML document, let us understand what is the label tag itself? The label tag helps in improving the usability of the web page for mouse users, as it can toggle the text inside it if the user clicks on it. Let us now discuss about the methods of changing the text of the label element using JavaScript. JavaScript allow us to use two inbuilt properties to change the text of any element in the HTML document, as listed below − Using the innerHTML ... Read More

Advertisements