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 288 views
1 answer 186 views
1 answer 214 views
2 answers 357 views
1 answer 260 views
1 answer 205 views
...