material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[system] initColorSchemeScript.tsx uses var instead of let

Open oliviertassinari opened this issue 1 year ago • 4 comments

Summary

We use var:

https://github.com/mui/material-ui/blob/9f4b846be96ee18733b6bd77eba2f54b1ceb9b04/packages/mui-system/src/InitColorSchemeScript/InitColorSchemeScript.tsx#L95

but this seems confusing. Why not let? For example, https://github.com/pacocoursey/next-themes/blob/bf0c5a45eaf6fb2b336a6b93840e4ec572bc08c8/next-themes/src/script.ts#L14 who use modern syntax.

Using let over var seems to have two benefits:

  • It's less prone to bugs https://sentry.io/answers/difference-between-let-and-var-in-javascript/.
  • It's easier to debug for developers, I would expect developers to not be used anymore to read code who uses var.

Motivation

I was confused by this looking into #43416.

oliviertassinari avatar Aug 24 '24 17:08 oliviertassinari

Hi, would you like to create a PR?

ilyastorunn avatar Aug 26 '24 12:08 ilyastorunn

Hi, would you like to create a PR?

Hey @ilyastorunn! I can do that, but go ahead if you have one ready.

ishon19 avatar Aug 26 '24 13:08 ishon19

Hi @oliviertassinari, var might have been used because the code was written in an environment where ES6 (let and const) was not supported, or it’s older code.

m-sathish-varma avatar Aug 27 '24 10:08 m-sathish-varma

I can pick this up if you like?

Michael-Hutchinson avatar Aug 27 '24 19:08 Michael-Hutchinson