prepare123
prepare123

Reputation: 165

can I use javascript in typescriptFile?

hi I'm get started typescript. I studied that typescript is javascript's super set So We can use javascript in Typescript File.

I'm wrote this code.

const words = '1,2,3,4'.split(',');
let sum = 0;
words.forEach(w => sum += parseInt(w));
console.log('sum:   ${sum}');

that's output should be in console

sum: 10

but that's result was

sum: ${sum}

I studied that in ES6 ' ${} 'means expression like Kotlin
can I use ES6 expression in TS ? I'm using WEBSTORM

Upvotes: 0

Views: 44

Answers (1)

pfcodes
pfcodes

Reputation: 1086

Wrap the string with back ticks (`) instead of single quotes (') and it will work.

Upvotes: 1

Related Questions