learn
Null check gotchas
· ☕ 1 min read
Beware of these null check gotchas. Consider this code - 1 2 3 4 5 6 7 const sum = null; if (sum) { console.log("valid sum"); } // nothing printed The above code shows expected behaviour. Nothing is printed since if(sum) returns false. Now, try the code below.

Assigning default values while object destructuring
· ☕ 1 min read
Easily assign default values while destructuring objects. Consider below code- 1 2 3 4 const obj = { x: 9, y: 1 }; const { x, y } = obj; console.log(x, y); // 9 1 A typical destructuring of objects, this code assigns x and y variables to the x/y props of object obj.

Use functional components in Vue
· ☕ 1 min read
Use light-weight functional components if you want stateless components. Components consist of many different parts in Vue - Data computed properties methods etc. Data property in particular stores states of the component, and enables the component to react to prop changes by keeping track of all that the component has to go through.

Evaluate and test Vue scripts using single HTML file
· ☕ 2 min read
How do you test your Vue code blocks and theories? Of course, you can simply have a test Vue project and throw in a single file component each time. Or, you could follow a simple structure to create a HTML/JS files. Or, you could just create everything in a single HTML page and clone it for quick tests.

Signify end of function with a return
· ☕ 2 min read
return terminates function whenever and wherever it is called. Consider this code block - 1 2 3 4 5 6 7 8 9 10 function getSum(x, y) { return x + y; let product = x * y; console.log(`sum is: ${x + y}, while product is ${product}`); } console.log(getSum(1, 5)); // 6 // no other console statements return will return the control to caller - no matter what state the function is in.

Three Invaluable shortcuts for type conversion in Javascript
· ☕ 1 min read
As Javascript developers we dream in type. Here are three quick and easy ways to convert from one type to the other in your Javascript code. Well, just kidding about the whole dream part. Most of us don’t quite care about types as much as we should. Anyhow, here are three quick ways to convert types -

Memoized Factorial Function in Javascript
· ☕ 1 min read
Get factorial of a given number using memoization techniques. Previously we have seen how memoization can be used in a reusable function to get all the advantages of memoization, without the complexity. Today, let us see one more practical example - get factorial of a given number. First, create a function to calculate factorial.

With statement in Javascript
· ☕ 2 min read
Avoid having to type your object notation multiple times using with statement. Consider the below code - 1 2 3 4 5 6 7 8 9 10 11 const earth = { name: "earth", satellite: "moon", position: 3 }; console.log("name:", earth["name"]); console.log("satellite:", earth["satellite"]); console.log("position:", earth["position"]); /* output name: earth satellite: moon position: 3 */ Typing “earth” everywhere can be quite laborious.

Prototype and property naming conflicts - shadowing issues in Javascript
· ☕ 2 min read
Be wary of prototype naming that can cause potential conflicts with one of the named objects. I have talked about using a non-emumerable property when defining a prototype, but what will happen if your prototype name conflicts with a prop name? You will loose quite a bit of hair - that’s what happens.

Git in VSCode
· ☕ 2 min read
I have been a great admirer and user of command line tools. They reduce so much time and energy while getting things done. But, on the other hand I have not been a reasonably good user of Git by itself. I could never come to terms with typing in one too many statements to get to where I was going.

Watch a specific prop of an object
· ☕ 2 min read
How do you watch a specific prop of an object? Is it useful at all? Watch is invaluable. It allows us to react to changes in the state and keep it that way through the life cycle of the component. Creating a watch is pretty simple. Consider the below example where we are monitoring the search text to respond to changes.

Measure Performance in Vue
· ☕ 1 min read
Measure your Vue application performance in a standard and consistent way. Previously we have seen how we can quickly measure performance in Javascript. How about Vue? Vue is the right mix of UI and business logic, and cannot be tested with standard back-end script execution speed. On the other hand, standard UI testing tools may prove to be a bit of an overkill due to the effort required to develop and maintain them.

Finally block has the final say
· ☕ 1 min read
Finally overrides any return statement from the try/catch. We write try/catch/finally for error handling in Javascript - 1 2 3 4 5 6 7 8 9 10 11 function tryTryTry() { try { return 4; } catch (e) { console.log(e); } finally { return 42; } } console.log(tryTryTry()); //42 The function returns 42 and not 4.