Tuesday, September 15, 2015

JavaScript - Tips 2 - Comparison

"use strict";
function fncComparison()
{
var firstVal = 1;
var secondVal = "1";
// with type coercion
if (firstVal == secondVal)
{
alert('Success with ==');
}
else
{
alert('Not equal when ==')
}
// without type coercion
if (firstVal === secondVal)
{
alert('Success with ===');
}
else
{
alert('Not equal when ===')
}
//Also we can use!= and !==
}
view raw Comparison.js hosted with ❤ by GitHub

No comments:

Post a Comment