3
let thesentence = 'I having a good day'
console.log(thesentence.substr(0,4))

the substr has a strikethrough effect, but using substring is fine.

starball
  • 20,030
  • 7
  • 43
  • 238
  • It's deprecated because it's never been part of the standardized language. It wasn't in the ECMAScript 1 or 2 specs at all, and only appears in ECMAScript 3 in Section B.2 ("Additional Properties") (and subsequent editions in similar annexes through to today [ES2022 draft as of this writing]). See [more](https://stackoverflow.com/questions/52640271/why-is-string-prototype-substr-deprecated) – ninhjs.dev Sep 15 '22 at 04:15

1 Answers1

1

It's crossed out because it's deprecated. That's a JS/TS VS Code feature that deprecated things are displayed with a strikethrough effect.

If you mouseover it and wait for the hover info to appear, you'll see this:

@deprecated — A legacy feature for browser compatibility

The @deprecated annotation in the doc comment of the typings (defined by lib.es5.d.ts (part of TypeScript)) is what makes VS Code know that it's deprecated. You can find the change that marked it as deprecated in the TypeScript typings in this commit: Update lib types to mark Annex B as deprecated (#43710)

To read about why substr is deprecated, see Why is String.prototype.substr() deprecated?.

starball
  • 20,030
  • 7
  • 43
  • 238