How to concatenate string with integer in JavaScript

4 Answers

0 votes
const str = "The number is ";
const num = 42;

let result = str + num;

console.log(result); 

 
     
/*
run:
     
The number is 42
     
*/

 



answered Jun 17, 2025 by avibootz
0 votes
const str = "The number is ";
const num = 42;

let result = `${str} ${num}`;

console.log(result); 

 
     
/*
run:
     
The number is 42
     
*/

 



answered Jun 17, 2025 by avibootz
0 votes
const str = "The number is ";
const num = 42;

let result = str + String(num);

console.log(result); 

 
     
/*
run:
     
The number is 42
     
*/

 



answered Jun 17, 2025 by avibootz
0 votes
const str = "The number is ";
const num = 42;

let result = str + num.toString();

console.log(result); 

 
     
/*
run:
     
The number is 42
     
*/

 



answered Jun 17, 2025 by avibootz

Related questions

2 answers 182 views
1 answer 101 views
1 answer 125 views
2 answers 246 views
1 answer 175 views
1 answer 119 views
...