DEV Community

Discussion on: Know the difference between theses JS concept in order to skill up #1

Collapse
aarone4 profile image
Aaron Reese

Use it if you need to declare a variable globally and modify it in a function and the changed value to be available globally. Probably best to leave comments as well as this would be unusual behaviour. There are likely other ways to achieve your logic as well

Collapse
codeoz profile image
CodeOz Author

Yes and moreover, it can be dangerous to create global variable in general since you can easily override it

Thread Thread
aarone4 profile image
Aaron Reese

Sort of. You should declare it globally BECAUSE you intend to modify it within a localised scope. This is how the js frameworks work. Vue is effectively a Global object which can have it's properties manipulated by the functions within it. but then we are getting into immutability and state management.