0

I am actually following a course of javascript and came across a piece of code where he say if true then do {} but what is true not specifically explained

//scope.js
let a = 'JavaScript' // is a global scope it will be found anywhere in this file
let b = 10 // is a global scope it will be found anywhere in this file
function letsLearnScope() {
  console.log(a, b) // JavaScript 10, accessible
  if (true) {
    let a = 'Python'
    let b = 100
    console.log(a, b) // Python 100
  }
  console.log(a, b)
}
letsLearnScope()
console.log(a, b) // JavaScript 10, accessible

The issue is this code working fine not giving error my question what true he is talking about

sarangkkl
  • 773
  • 3
  • 15
  • It's just a example of creating another block in which a new `a` and `b` are created. What they refer to inside that block is not the same as what they refer to outside – CertainPerformance May 09 '22 at 01:57
  • what he mean by if true what is true what he talking about – sarangkkl May 09 '22 at 01:59
  • `true` is a `Boolean`, when used by itself as condition, it will always pass. In your example it could be replaced by `if(1){...}` or omitted the condition all together and create new scope with just curly brackets: `{ let a ='Python' }` without the `if(true)` – vanowm May 09 '22 at 01:59
  • whats the point of saying ```if (true)```? – seriously May 09 '22 at 01:59
  • Like I said *It's just a example of creating another block*. `{` starts a block. – CertainPerformance May 09 '22 at 02:00

0 Answers0