JaeYeopHan / tip-archive

πŸ“¦ Archiving various development tips. If you watch this repository, you can get issues related to the newly registered development tip from the GitHub feed.
https://www.facebook.com/Jbee.dev/
245 stars 8 forks source link

Use `const` rather than `let`, as always #80

Open JaeYeopHan opened 2 years ago

JaeYeopHan commented 2 years ago

❌ 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) πŸ₯°
  }
}
brightparagon commented 2 years ago

μ–΄μ°Œ 이런 일이..