Why use variable for age?


#1

Why does age need to be stored in a variable? It's only used once, right? Couldn't you just say:

if (prompt("What's your age") < 13) {

}

#2

Because this would be more confusing for some learners maybe?

If it's not in a variable, and it's done like you've done it, it won't be reusable and it makes the conditions in the if statement look more complex, which not many people like.


#3

Gotcha. So unless you need to reuse it, it's just a question of human readability vs. resource usage. Not that this one variable here is gonna bring a computer to a halt, but in principle :slight_smile:


#4

Exactly.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.