Guys is it possible to compare to function in JavaScript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Guys is it possible to compare to function in JavaScript?

like function f1() { var a=10; } function f2() { var b=10; } and i want to compare it. how can i do that. give an example if you can.

22nd Feb 2018, 5:17 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
6 Answers
+ 5
you can use this window.onload=function f1() { var a=10; var b=10; if(a===b){ document.write("Same") }else { document.write("not Same") } }
22nd Feb 2018, 5:25 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 4
@mickel 👍
22nd Feb 2018, 5:43 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
but is it possible to compare to function.
22nd Feb 2018, 5:37 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 2
I do not think he wants to compare the value of the variables within the functions. And of course you can compare two functions. But for this you would have to modify your code a bit: let myFunction = function () { let a = 10; console.log (a); } let myOtherFunction = function () { let b = 10; console.log (b); } The biggest change is that your functions are currently hosted in a variable (you can use it as you would use any function. Example: myFunction(); ) In any case, when comparing both functions, the result will always be false: console.log (myFunction === myOtherFunction); > false For the result to be true, you would need something like: let a = myFunction; console.log (myFunction === a); > true
22nd Feb 2018, 5:41 AM
Mickel
Mickel - avatar
+ 2
thanks Guys actually i am making my self project so i need this things.
22nd Feb 2018, 3:31 PM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 1
var a_ var b_ function f1(){...} function f2(){...} a_ = f1() b_ = f2() if (a_==b_){ .. }else {...}
22nd Feb 2018, 5:37 AM
Alexander Firsov
Alexander Firsov - avatar