Return and console.log , variable declaration with and without using 'var' in javascript


#1

Hi. I got something in my mind. Actually two questions.
1.Difference between declaration using var and without var?
2. Difference between return and console.log?


#2

@terasolver40977,
google search
== discussions / opinions ==
javascript variable declaration site:stackoverflow.com
= http://stackoverflow.com/questions/2485423/is-using-var-to-declare-variables-optional

javascript return vs console.log site:stackoverflow.com
= http://stackoverflow.com/questions/21020608/difference-between-console-log-and-return-in-javascript

( also look into the =Related= column )


== the Book ==
javascript return site:developer.mozilla.org


#3
  1. var is used to protect the global scope by scoping variables to their function enclosures. When omitted from a variable definition, the variable is auatomatically hoisted to the top of global scope where it is volatile and may collide with other variables. Best practice? Use var in all variable declarations when defining new variables.
  2. return and console.log are not comparable. They are not interchangeable and do not share in any functional roles.

#4

thanks man for helping


#5

2 posts were split to a new topic: Why are all of our codeacademy Javascript exercises written using either const or let


Why are all of our codeacademy Javascript exercises written using either const or let
#6