variable with a number and a string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

variable with a number and a string

how to declare a variable with a number and a string in javascript? let carEngineSize = 2000cc ; i get error message

7th May 2023, 3:01 PM
akhil vaid
akhil vaid - avatar
4 Answers
+ 7
let carEngineSize = '2000cc'; Hint: Try to complete the JavaScript course for more information.
7th May 2023, 3:07 PM
JaScript
JaScript - avatar
+ 6
Declare just a string let carEngineSize = "2000cc"; Or do not put units let carEngineSize= 2000; And next at printing the data print the units: console.log(carEngineSize+ "cc");
7th May 2023, 3:04 PM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 2
Use in double quotes or you can use + sign carEngineSize = "2000cc";
7th May 2023, 4:16 PM
Aayush Chilkoti
Aayush Chilkoti - avatar
+ 2
the other option is to make it an object with two separate properties, eg let carEngineSize = { size: 2000, units: "cc" }
7th May 2023, 8:13 PM
Orin Cook
Orin Cook - avatar