r/learnjavascript • • Jul 19 '21

JavaScript Function Facts

255 Upvotes

27 comments sorted by

View all comments

Show parent comments

4

u/[deleted] Jul 19 '21

Reassign, yes, but not redeclare.

 let assignment = 3;
 assignment = true;

 let declaring = function() {}
 let declaring = false; // here will be a redeclaration error

-5

u/[deleted] Jul 19 '21

We’ll that’s not really redeclaration is it? You’re assigning 2 variables with the same name?

1

u/[deleted] Jul 19 '21

well it is. the first declaring would be of type 'function' while the second declaring would be a boolean. you can do that in var :

 var a = function() {};
 typeof a // "function"

 var a = false;
 typeof a // "boolean"

3

u/[deleted] Jul 19 '21

Interesting. Thanks for bringing this up!