I
I
ivan05122020-02-12 10:53:21
JavaScript
ivan0512, 2020-02-12 10:53:21

Why is it possible to call a function before the declaration?

Can you tell me why there is no error when I call a function before it is declared?
I understand that the function can be in a closure, but this is a potential bug.
For example, if I call test immediately after the declaration
5e43ae7e69a69225325364.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
ivan0512, 2020-02-12
@ivan0512

Typescript itself does not check this situation, you need to use a linter

N
nvdfxx, 2020-02-12
@nvdfxx

If you call test before the declaration of setCitiesError, then there will be an error, and if after, then setCitiesError will already be in memory

A
andre777-14, 2020-02-12
@andre777-14

In Javascript, this is called hoisting Read
here - https://developer.mozilla.org/en/docs/%D0%A1%D0%BB...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question