Could someone tell me what mistake I’m making that’s causing not having the same outputs as the result.
First file:
function four() {
return 4 + plus();
}
function nine() {
return 9;
}
function plus() {
return nine();
}
console.log(four(plus(nine())))
// Output: 13
Second file:
// I’ve added the above code into classes for demonstration purposes but it gives an error.
class A {
four() {
return 4 + plus();
}
nine() {
return 9;
}
plus() {
return nine();
}
}
class B {
constructor() {
this.a = new A();
}
result() {
console.log(this.a.four(this.a.plus(this.a.nine())))
}
}
var r = new B();
r.result();
// Output: return nine();
^
ReferenceError: nine is not defined
Thank you in advance.