What's the difference?

I recently learned about string conversion via `${}` but in MakeCode there is also the function “.toString”. What is the difference other than some template stuff? Next question uhh is one of them faster than the other(I don’t understand the inner working of MKCD) so it might be they are as fast as each other or smth.

well I know that in pure JavaScript ${} Grabs a Variable in a string like “Hi ${Name}” so it puts Name in there well to string just converts say a number to a string aka 0 becomes “0”

The difference is really just template stuff. I have personally never really used ${} strings, but I can see how they might make some code simpler and neater.

I did a pretty simple test and it seems that toString() is marginally faster. This test does have issues, but I tried to make it somewhat realistic to how you would use the 2 options differently in your code by adding the commas to the string. Even with the toString() method needing 2 “+” bits to add the commas, instead of only 1 for the ${} string, toString() still won, averaging ~215 vs ${} which averaged ~250. These are marginal speed improvements either way, so it probably doesn’t matter unless you’re using it hundreds of times every frame.


I did do more than just this test and toString() came out on top pretty much every time.

ahh cool(time to give you a solution)

Ooooh. So that’s what a solution looks like :eyes:

Did you make this with the Arcade > Global MakeCode Arcade Game Jam tag just so you could use the “solution” button? :smirking_face: