This is the first of a series of short posts about languages, patterns, frameworks or technologies that I have been exposed to recently for the first time.
Going through the introductory training material will get you there but these courses tend to start from a zero-programming knowledge. I’ve extracted some interesting bits from my experience here.
Number or String
var a = 4; var b = "2"; var c = a / b; c; 2
That is handy… but you have to be careful. The concatenation operator, just like in Java is the plus symbol,
+, and it will behave differently under similar circumstances to the first example. In the following case it will decide to concatenate rather than add the two numbers.
var a = 4; var b = "2"; var c = a + b; c; "42"
Note that the other simple operators, minus and multiplies, behave like division so that real numbers and their string representations will work as expected.
The Same or Really the Same
var a = 42; var b = "42"; var eq = a == b; eq; true
That might not be what we need, however, as we might want to check type also. Introducing the triple equals,
===, operator. This will check both the type and value.
var a = 42; var b = "42"; var eq = a === b; eq; false
One further point is that if you want to negate the above operator, there are also two choices for doing “not equals”. You can use an exclamation mark with equals (
!=) to negate the double equals, or the an exclamation mark with two equals (
!==) to negate the exactly equals. In both cases, the first equals symbol changed to