-1

I wonder if it is possible to declare 'const exch' as empty first since I need that variable to be global for a loop function?

The below does not seem to work?

const exch;
exch = new ccxt.kortux ({ enableRateLimit: true })
Andreas
  • 1,121
  • 4
  • 17
  • 34
  • 9
    You can't. `const` is a value that is set once declared, and it never can be reassigned thereafter. – Get Off My Lawn Feb 13 '19 at 22:01
  • 4
    [Const in javascript? When to use it and is it necessary](https://stackoverflow.com/q/21237105/215552) – Heretic Monkey Feb 13 '19 at 22:01
  • 1
    _The value of a constant cannot change through reassignment, and it can't be redeclared_ – Shidersz Feb 13 '19 at 22:02
  • 5
    @GetOffMyLawn `const` values can change, they just can't get reassigned. – JohanP Feb 13 '19 at 22:02
  • 1
    More to the point, unlike readonly in say C# or Java (which allow deferred assignment in certain contexts), const requires the expression at the declaration site - this is part of the syntax. – user2864740 Feb 13 '19 at 22:03
  • I see, then I understand. Then I need to declare the const as it is in one go. Thank you for pointing that out! – Andreas Feb 13 '19 at 22:04
  • Why not just write the usual `const exch = new ccxt.kortux ({ enableRateLimit: true })`? What do you mean by "*I need that variable to be global for a loop function*", can you show an example? – Bergi Feb 13 '19 at 22:44

1 Answers1

0

Change your code to

let exch;
exch = new ccxt.kortux ({ enableRateLimit: true })

or even better:

const exch = new ccxt.kortux ({ enableRateLimit: true })

const declarations are not able to be redefined, let declarations are.

Scott Z
  • 352
  • 1
  • 7