fcf.equal() function
Package: fcf-framework-core
File: fcf-framework-core:fcf.js
Available from version: 2.0.2
Compares two values for equality.
The objects being compared can be simple types, arrays, objects,
When comparing two
Arguments
- First comparison value
- Second comparison value
- If it is true , then a strict comparison is used for comparison === simple types, and for objects, a check for the equality of designers is still performed.
Result
- Returns true if two values are equal.
When comparing two
Example: Function application
console.log(`0 == 0: `, fcf.equal(0, 0));
console.log(`"0" == 0: `, fcf.equal("0", 0));
console.log(`"0" === 0: `, fcf.equal("0", 0, true));
console.log(`"a" == "a": `, fcf.equal("a", "a"));
console.log(`"a" == "b": `, fcf.equal("a", "b"));
console.log(`0 == false: `, fcf.equal(0, false));
console.log(`0 === false: `, fcf.equal(0, false, true));
console.log(`NaN == NaN: `, fcf.equal(NaN, NaN));
console.log(`NaN === NaN: `, fcf.equal(NaN, NaN, true));
Output:
0 == 0: true
"0" == 0: true
"0" === 0: false
"a" == "a": true
"a" == "b": false
0 == false: true
0 === false: false
NaN == NaN: true
NaN === NaN: true
Example: Comparison of arrays
console.log(`[1] == [1]: `, fcf.equal([1], [1]));
console.log(`["1"] == [1]: `, fcf.equal(["1"], [1]));
console.log(`["1"] === [1]: `, fcf.equal(["1"], [1], true));
console.log(`[1,2] == [1]: `, fcf.equal([1,2], [1]));
console.log(`[[1]] == [[1]]: `, fcf.equal([[1]], [[1]]));
console.log(`[[1]] == [[2]]: `, fcf.equal([[1]], [[2]]));
Output:
[1] == [1]: true
["1"] == [1]: true
["1"] === [1]: false
[1,2] == [1]: false
[[1]] == [[1]]: true
[[1]] == [[2]]: false
Example: Comparison of objects
{
let result = fcf.equal({v: 1}, {v: 1});
console.log(`{v: 1} == {v: 1}: `, result);
}
{
let result = fcf.equal({v: 1}, {v: 2});
console.log(`{v: 1} == {v: 2}: `, result);
}
{
let result = fcf.equal([1], [1]);
console.log(`[1] == [1]: `, result);
}
{
let result = fcf.equal([1], [2]);
console.log(`[1] == [2]: `, result);
}
{
let result = fcf.equal("1", 1);
console.log(`"1" == 1 : `, result);
}
{
let result = fcf.equal("1", 1, true);
console.log(`"1" === 1 : `, result);
}
Output:
{v: 1} == {v: 1}: true
{v: 1} == {v: 2}: false
[1] == [1]: true
[1] == [2]: false
"1" == 1 : true
"1" === 1 : false