I
I
Ignatiy22019-04-12 17:40:22
Programming
Ignatiy2, 2019-04-12 17:40:22

Is it bad to declare variables at the beginning of the code?

I'm relatively new to programming (learning js). And I've got into the habit that when I'm practicing, doing some little To-Do web applications, I declare variables at the beginning of the code. But now I read that this is just a terrible habit. Do you think this is so?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2019-04-12
@Ignatiy2

For JS, it's quite normal. This is not a good practice for statically typed languages, but in JS it is quite normal.

Q
q2zoff, 2019-04-13
@q27off

Normal practice is to combine initialization and declaration of variables. At least the code reads better. You don't have to remember which variable you're assigning to and whether it overwrites previous data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question