React Js Concat String with Space
React Js Concat String with space:To concatenate a string with a space using a literal template in React.js, you can use the backtick () character to create a template string and the
${}syntax to inject variables. For example, suppose you have two variables
firstNameand
lastName`. To concatenate them with a space in between, you can write
Thanks for your feedback!
Your contributions will help us to improve service.
How can we concatenate two strings with a space in React.js?
In the given React.js code snippet, a functional component called App
is defined. It creates four variables: firstName
with the value 'John', lastName
with the value 'Doe', age
with the value 30, and occupation
with the value 'Engineer'.
Using template literals, the variables firstName
and lastName
are concatenated with a space in between, resulting in the fullName
variable holding the value 'John Doe'. The age
and occupation
variables are concatenated with the corresponding labels, separated by a pipe character, resulting in the bio
variable holding the value 'Age: 30 | Occupation: Engineer'.