Search In
• More options...
Find results that contain...
Find results in...

# Simple JS code.

Go to solution Solved by Vinod Bahadur Thapa,

first

`console.log(bar(6)) will call the function bar(6)  //  [6 as a parameter]`

then

`function bar(x) { var y = 3; return foo(x*y);  // now here x=6;  than foo(3*6) = foo(18)  , now this will call foo() function `

now

`function foo(b) { var a = 5; return a*b+10 } // here b=18 so 5*18 + 10 ... and rule says * priority > plus sign so 90+10 = 100`

which will return 100 and this is the final output

please tell me this gif is wrong... right? that return 28 part is coming from where I have no idea.

If it is not broken, let's fix till it is.

##### Share on other sites

You got the BODMAS wrong, 5*18 + 10 = (5*18) + 10 = 100

AMD R7 2700 | 2x8 3000Mhz Corsair LPX | B450M Mortar  | GTX 1070 6GB | Noctua DH-N14 | Corsair MP50 480GB | BitFenix Phenom M | Corsair AX760 | Khadas Soundboard + JDS Labs Atom | Debian 10 SID

Thanks let me know if I said something useful. Cheers!

##### Share on other sites

I don´t know, the image flickers and changes all the time until it stops.

##### Share on other sites

1 minute ago, kidanime3d said:

You got the BODMAS wrong, 5*18 + 10 = (5*18) + 10 = 100

I didnt create the gif, found it online.

so at the end of the gif it should return 100 right?

If it is not broken, let's fix till it is.

##### Share on other sites

Just now, mrchow19910319 said:

I didnt create the gif, found it online.

so at the end of the gif it should return 100 right?

Yes, 100.

The creator got the end of the gif wrong

AMD R7 2700 | 2x8 3000Mhz Corsair LPX | B450M Mortar  | GTX 1070 6GB | Noctua DH-N14 | Corsair MP50 480GB | BitFenix Phenom M | Corsair AX760 | Khadas Soundboard + JDS Labs Atom | Debian 10 SID

Thanks let me know if I said something useful. Cheers!

##### Share on other sites

If you're using Chrome or Firefox, you can test it yourself. Press F12 and click on "Console" in the developer window. Then paste that program inline:

`function foo(b) { var a = 5; return a*b+10 } function bar(x) { var y = 3; return foo(x*y); } console.log(bar(6))`

and hit enter. Should print out 100 as written.

##### Share on other sites

first

`console.log(bar(6)) will call the function bar(6)  //  [6 as a parameter]`

then

`function bar(x) { var y = 3; return foo(x*y);  // now here x=6;  than foo(3*6) = foo(18)  , now this will call foo() function `

now

`function foo(b) { var a = 5; return a*b+10 } // here b=18 so 5*18 + 10 ... and rule says * priority > plus sign so 90+10 = 100`

which will return 100 and this is the final output