How do I write the result of a function into a variable?
-
There is a function that returns a string
I want to write this line into a variable
but if you write let abc = function (arg) then abc equals undefinedJavaScript Anonymous, Jun 2, 2019 -
function myFunc(arg) {
return arg
}
let result = myFunc('Строка')
console.log(result) // СтрокаAnonymous -
but if you write let abc = function (arg), then abc is undefined
This is exactly how you need to write. But the function must return a value.
In this case, function is the conditional name of the function. Since this is a function word, you cannot use it for naming.
Show the function itself.Anonymous -
There is a function that returns a string
...
if you write let abc = function (arg), then abc equals undefined
Try it
let abc = /* please give me a string */ function(arg)
If it doesn't work, then only 3 options are possible:
1. Most likely: this is a language bug, you have to accept and never use these buggy lines and functions.
2. The function is asynchronous. The function returns a string sometime later.
3. The function does not return a string. But wait, this can't be!Anonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!