"return", "returns" in javascript, if in fact it is "displayed", "output"? What does the "return"?
Closed due to the fact that the essence of the question is not clear to the participants from Vlad from Moscow , Grundy , andreymal , Stepan Kasyanenko , 0xdb on March 18 at 14:13 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
- onenot one conclusion to the screen are one. - ThisMan
- Kromster, that's why there was a change, if everything is clear? And now you have done more confusing ... - Since
- @Since The point is not clear. - Vlad from Moscow
- Question for META or Russian stackexchange)) - DaemonHK
- fourThe function returns the result of its work to the one who called this function. It is as if you sent a friend for a pivasik to the nearest store, and then he returns to you the result of his work - a bottle of light. The result can be drunk, and you can put in the fridge. So with the result of a function call: the returned value can be displayed on the screen, but you can do nothing with it. The conclusion on the screen and the return are two completely different and unrelated actions - andreymal
4 answers
In programming, these operations are separate and not synonymous, there has obviously been some misunderstanding when using them. I can assume that you met these operations when they go one after another and the author of the article / book / manual omitted the details.
For a short example, so to speak, the addition operation will return the sum:
console.log(5 + 7)
But the correct phrase will sound like "we display what the number addition operation returned to us." That is, two operations follow each other, but I omit part of the phrase, since my goal is to tell about addition.
In fact, separate operations take place and the returned result may not be displayed on the screen.
//возвращаем результат операции суммирования a = 5 + 7 //выводим на экран совершенно другую фразу console.log("у меня есть результат, но я вам его не покажу") //выводим значение переменной a на экран (никакого возврата тут нет) console.log(a)
Usually “returned” they say when some operations take place and we get the result. These can be expressions and functions as a rule. I hope it will be so clearer.
"return", "returns" in javascript, if in fact it is "displayed", "output"? What does the "return"?
Given what is said about the function, the function returns the value after it has worked. What to do with this value is then decided by the programmer, and this is not necessarily an output to the screen.
function summ(a, b) { return a + b; } const result = summ(5, 10); // функция возвращает значение, но ничего не выводит на экран // потом мы вообще можем это на бэкенд отправить
These are completely different operations. For example, console.log()
prints text to the screen, but returns nothing:
x = console.log("Hello world!"); // выводит текст на экран и возвращает результат работы в переменную х console.log(x); // х - undefined, т.е. console.log() ничего не возвращает
And, for example, Math.sin(x)
returns the sine of x, but displays nothing on the screen.
Because we display what some function has returned to us. (or do not print, but use something else)