Taswar Bhatti
Practical guides on AI agents, LLM security, C#/.NET and Cloud, from Taswar Bhatti
Archive: August 2014
conversion

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 and then it flips it, and the second operator flips it back to the correct Boolean value.

… Read the rest “JavaScript conversion tips”
javascript

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

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 double pipe operator ||, where the object is null or undefined.

… Read the rest “Learn to love default value in Javascript”
Javascript

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 the value is equal and if the type is equal.

Lets look at an example below.

The reason for the === operator to return false is due to … Read the rest “Learn to love the === operator in JavaScript”

Javascript quick tip debugger

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

One could then add a debugger; statement … Read the rest “Javascript quick tip debugger statement”

Javascript

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 global namespace, all variables used inside the function will not be visible to the outside scope. You may have seen this kind of code, something along the line of:

For example the variable defined below bar will not be able to access it outside the scope.
IIFE provides a protection/encapsulation to your code.

… Read the rest “Keep yourself protected with modular JavaScript”
UA-4524639-2