
I am new in learning Javascript and as I was following the tutorial I found that console.log(name); got (name) struck through in such a way claiming it is "Deprecated".
If there is an explanation on what that means or what I should do to remove that strike, I would be really thankful.
Because you used var name = ..., TypeScript thinks you are referring to window.name, which TypeScript considers deprecated. You can fix this error by:
anotherName -var anotherName = 'Bob'
console.log(anotherName)
(() => {
var name = 'bob'
console.log(name)
})()
I think this is due to the fact that a 'loose' variable in a browser, declared with var, outside of a function is just going to end up pointing to:
window.name
And window.name has a special meaning, and is indeed deprecated.
It's a quirk of the language. If you didn't intend to create the variable in a global scope, you might be better off just declaring it in a function.
This will not have the same problem:
function main() {
const name = 'Foo';
}
main();
Generally it's a good idea to avoid creating any global symbols unless you explicitly intend to.