Significance of return keyword in javascript -


I am new to javascript, if the question seems silly, ignore it. What is the importance of the return keyword in the code of the third last line when we can cancel it?

  function showName (first name, last name) {var nameIntro = "Your name is"; The function is doing the same thing, even if I can leave the "return" here (the name of the first name + + + + + + last name);}  

In your example, you should return return is not required because your function does not produce an object or value, it only does something (this gives the string warning)

Suppose, however, that you name the intro You want to save the value of the string and use it later. Your function can be modified to return the value, which can be saved as a variable, the following code will give the same result, but the return is used:

  function showName (first name, last name) {var nameIntro = "your name is"; function makefinalname () {return name interna + firstname + " "+ Last name;} return makeFullName ();} var nameString = showName (" Michael "," Jack Sun "); alert (nameString);  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -