+ 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.
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")
}
}
+ 4
@mickel š
+ 2
but is it possible to compare to function.
+ 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
+ 2
thanks Guys actually i am making my self project so i need this things.
+ 1
var a_
var b_
function f1(){...}
function f2(){...}
a_ = f1()
b_ = f2()
if (a_==b_){
..
}else {...}