In this post I will write about some tips on JavaScript Conversion from type to values etc. Tip 1: Boolean values In JavaScript one can use the double not (!!) to convert a variable to a Boolean. What the !! operator (poor man casting) does is, it first cast the data to a true Boolean […]
Here is another quick tip on JavaScript, the default value in Javascript. If you are coming from the C# world you may have seen something along the line of
1 |
string str = person.FirstName ?? "Unknown"; |
The above code shows the ?? for null coalescing operator in C#, don’t confused it by the generic default value. In JavaScript, there is the […]
In JavaScript there are two types of equality operator, the === and the !== , sorry I forgot to mention their evil twin == and != . tsdr; (too short didn’t read) Use three equals unless you fully understand the conversions that take place for two-equals. Basically what the triple equal (===) compares is if […]
Here is Javascript quick tip debugger for Javascript developers, there is a debugger statement in JavaScript, which invokes any available debugging functionality. e.g setting a break point, and if there is no debugging functionality available the statement has no effect. Let’s say you wish to debug a function
1 2 3 4 5 6 7 8 |
var x = (function f() { var message = 'hello world'; if(typeof window.console !== 'undefined') { console.log(message); } else { alert(message); } })(); |
One could then add a debugger; […]
Here is another quick tip on creating modular JavaScript, namely function wrappers, or more technically called Immediately-Invoked Function Expression (IIFE). A self-invoking anonymous function runs automatically/immediately when you are create it, but don’t confuse it with document.ready or window.onload. The basic of IIFE is to use a wrapper so that it does not pollute the […]
Here is a quick tip for JavaScript falsy conditions for programmers or for people who come from Java or C#. In Java and C# when we thinks of using a compare conditions in a if statements, we tend to use something along the line of:
1 2 3 |
if(val != null && val.length > 0) { //do stuff } |
We tend to bring this baggage of knowledge to […]
Jade Node.js Template Engine, Include & Template Inheritance Part 6 In this post, I will write about using includes and template inheritance in Jade template engine. You can also check out my previous 5 post on Jade. Jade Node.js Template Engine Part 1 Jade Node.js Template Engine Basics Syntax Part 2 Jade Node.js Template Engine […]