A
A
AlexNew222022-04-22 00:01:17
JavaScript
AlexNew22, 2022-04-22 00:01:17

Why doesn't the toString method work when displaying the result?

Why am I getting the result of a function in the console and not a calculation?

function func(n1) {
    return function foo(n2) {
        foo.valueOf = () => n1 + n2
        foo.toString = () => n1 + n2
        return func(n1 + n2)
    }
}

const fo = func(3)
console.log(fo(10))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
low molecular macro, 2022-04-22
@AlexNew22

function func(n1) { 
  const foo = n2 => func(n1 + n2)
  foo.toString = () => n1
  return foo;
}

const fo = func(3)
console.log(fo(10))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question