1

I defined a variable and assigned it a function which had syntax error. It throws error. Now, I am unable to use that variable for anything, it always say 'Thrown: ReferenceError: variable is not defined'

> let bg = 'asasas-123d'
undefined
> let fd = bg.substring(indexOf('-')+1)
Thrown:
ReferenceError: indexOf is not defined
> let fd = bg.substring(bg.indexOf('-')+1)
Thrown:
SyntaxError: Identifier 'fd' has already been declared
>  fd = bg.substring(bg.indexOf('-')+1)
Thrown:
ReferenceError: fd is not defined
> let  fd = bg.substring(bg.indexOf('-')+1)
Thrown:
SyntaxError: Identifier 'fd' has already been declared
> fd = bg.substring(bg.indexOf('-')+1)
Thrown:
ReferenceError: fd is not defined
> fd
Thrown:
ReferenceError: fd is not defined
> console.log(fd);
Thrown:
ReferenceError: fd is not defined
dragon
  • 51
  • 3
  • Note that `indexOf` is a property of iterable objects, not a variable. – Seblor Apr 23 '19 at 06:36
  • The console execution context is weird. *When there's assignment, the right-hand side is parsed first; if the right-hand side throws an error, it never gets to the left-hand side, and the variable declared with let never gets properly initialized; it'll stay in the demilitarized zone / temporal dead zone forever*. You probably meant to use something like `bg.substring(bg.indexOf`, because `indexOf` is not a standalone function (you might consider using a regular expression instead, too) – CertainPerformance Apr 23 '19 at 06:36
  • 1
    Hi Dragon! Welcome to the boards. It looks like you have a typo which may be the cause of this entire error. let fd = bg.substring(indexOf('-')+1) I believe you mean bg.indexOf – Chris Ngo Apr 23 '19 at 06:38
  • yes, i meant that only. I made a typo. I am actually confused about why is it not allowing me to access that variable again? If I use 'let fd = something' it says it has been already declared. If I use 'fd = something' it says it is not defined. – dragon Apr 23 '19 at 07:30

1 Answers1

0

Just restart your terminal and run this:

> let bg = 'asasas-123d'
> let fd = bg.substring(bg.indexOf("-") + 1))
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
  • 1
    My question is How can a variable be declared but not defined. I know that was a typo and I corrected in later steps, but it is not allowing me to do so. – dragon Apr 23 '19 at 07:31