Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use const rather than let, as always #80

Open
JaeYeopHan opened this issue Dec 19, 2021 · 1 comment
Open

Use const rather than let, as always #80

JaeYeopHan opened this issue Dec 19, 2021 · 1 comment
Labels
for: share For sharing issue related: typescript Related TypeScript language

Comments

@JaeYeopHan
Copy link
Owner

❌ Hey, What's the matter?

function calculate() {
  let arrayOrString = somethingFunc();
  let isArray = Array.isArray(arrayOrString)

  if (isArray) {
    console.log(typeof arrayOrString) // string | object (array) 💥
    // isn't array?
  }
}

Come back to const!

-  let arrayOrString = somethingFunc();
+  const arrayOrString = somethingFunc();
-  let isArray = Array.isArray(arrayOrString)
+  const isArray = Array.isArray(arrayOrString)

so,

✅ That's right

function calculate() {
  const arrayOrString = somethingFunc();
  const isArray = Array.isArray(arrayOrString)

  if (isArray) {
-    console.log(typeof arrayOrString) // string | object (array)
+    console.log(typeof arrayOrString) // object (array) 🥰
  }
}
@JaeYeopHan JaeYeopHan added for: share For sharing issue related: typescript Related TypeScript language labels Dec 19, 2021
@brightparagon
Copy link

어찌 이런 일이..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: share For sharing issue related: typescript Related TypeScript language
Projects
None yet
Development

No branches or pull requests

2 participants