Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my variable show it's deprecated?

Tags:

javascript

My editor (VS Code) shows that my variable name is deprecated. The variable name is struck out from the 2nd line. Can you help?

let name = 'Mark';
name = 5;
console.log(name);
like image 573
JITTU VARGHESE Avatar asked Dec 20 '20 11:12

JITTU VARGHESE


People also ask

What does it mean if a variable is deprecated?

If a variable that is specified with the deprecated attribute is used, the compiler issues a warning message to indicate that the variable is not recommended to be used. Warning messages are issued only for uses but not declarations of deprecated variables.

What does it mean when something is deprecated in VS code?

Deprecation, in its programming sense, is the process of taking older code and marking it as no longer being useful within the codebase, usually because it has been superseded by newer code. The deprecated code is not immediately removed from the codebase because doing so may cause regression errors.

What does deprecated mean in JS?

The JavaScript warning "expression closures are deprecated" occurs when the non-standard expression closure syntax (shorthand function syntax) is used. This syntax is now removed and the warning message is obsolete.

What is a deprecated function?

Deprecated refers to a software or programming language feature that is tolerated or supported but not recommended. A deprecated attribute or feature is one that may eventually be phased out, but continues to be used in the meantime.


1 Answers

In a browser, the global name variable has special meaning. This has caused people a lot of confusion over the years as they tried to create their own global variable named name and then found it coerced into a string.

The checker you are using doesn't appear able to special case an assignment to name if it follows a declaration of let name.

You can see that the message goes away if you put the code inside a function.

Screenshot demonstrating the above

like image 89
Quentin Avatar answered Oct 19 '22 15:10

Quentin