How to Concat String in React JS?
Nov 04, 2022 . Admin
Hello Friends,
In this short tutorial we will cover how to concat string in react js. This tutorial will give you a simple example of concat string in react js. This post will give you a simple example of react js two string concat string. I explained simply about react js two string concat with variable.
In this example concat string in react js. I will step by step concat string in react js. Append one string to another using the + operator.
So, let's start following example:
Step 1: Create React JS AppIn this step, open your terminal and execute the following command on your terminal to create a new react app:
npx create-react-app reactjs-my-exampleStep 2: Create index.js file src/index.js
import React from 'react'; import ReactDOM from 'react-dom/client'; const hello = "Hello "; const result = hello + " Welcome"; const App = () => { return ( <div> <h1>{result} Mywebtuts.com</h1> </div> ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />);Run React JS App:
npm start
Output:
Hello Welcome Mywebtuts.com
I hope it can help you...