Navigate back to the homepage

# How to multiply two numbers in react js?

Infinitbility
React
October 13th, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To multiply two numbers in react js, use the * multiplication operator it will multiply it if your value datatype is a number else if your value datatype is string first convert it using parseInt() and then perform multiplication operation.

In the following example, we will take the sample numbers, and strings and perform a multiply operation using the * multiplication operator.

## Multiplying Two numbers example

`.css-1chxjt6{position:absolute;right:22px;top:24px;padding:8px 12px 7px;border-radius:5px;color:#6f7177;-webkit-transition:background 0.3s ease;transition:background 0.3s ease;}.css-1chxjt6:hover{background:rgba(255,255,255,0.07);}.css-1chxjt6[data-a11y="true"]:focus::after{content:"";position:absolute;left:-2%;top:-2%;width:104%;height:104%;border:2px solid var(--theme-ui-colors-accent,#6166DC);border-radius:5px;background:rgba(255,255,255,0.01);}@media (max-width:45.9375em){.css-1chxjt6{display:none;}}1let num1 = 3;2let num2 = 3;3num2 * num1; // 9`

## Multiplying Two string numbers example

`1let num1 = "3";2let num2 = "3";3parseInt(num2) * parseInt(num1); // 9`

Today, I’m going to show you How do i multiply two numbers in react js, as mentioned above here, I’m going to use the * multiplication operator.

Let’s start today’s tutorial on how do you multiply two numbers in react js.

In this example, we will do

• take an example of a number and string number state
• Multiplying two numbers example
• Multiplying two string numbers example
• print the output on the page screen
`1import React, { useState } from "react";2export default function App() {3  const [firstNum, setFirstNum] = useState(3);4  const [secondNum, setSecondNum] = useState(3);5  const [firstStr, setFirstStr] = useState("3");6  const [secondStr, setSecondStr] = useState("3");7  return (8    <div className="App">9      <h1>{`Multiplying two numbers example`}</h1>10      <p>{firstNum * secondNum}</p>11      <h1>{`Multiplying two string numbers example`}</h1>12      <p>{parseInt(firstStr) * parseInt(secondStr)}</p>13    </div>14  );15}`

In the above react js example, we have taken the sample numbers and string numbers state, and performed Multiplying two numbers example, and Multiplying two string numbers example.

I hope it helps you, All the best 👍.

### Output

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

### Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Request New Tutorial or Article on mail [email protected]

### Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

### How to subtract two numbers in react js?

An example of subtracting two numbers in react js with the step-by-step guide.

October 12th, 2022 · 1 min read

### How to find the length of a string in an array in Javascript??

An example of get length of array string in javascript with the step-by-step guide.

October 11th, 2022 · 1 min read