Type Casting in Javascript

Don’t know how to type? Get a typewriter. I always wanted to say that. But, if indeed you don’t know types - you can always head over to Javascript types to know more**. So, you know there are types. And, you also know that there can be many a problem in the lousy world of loose typing. (I just felt like the next S waxing such eloquence). The only choice to make here is to know more about how to convert from one type to other, and remain type-safe. And, that will quickly become second nature to your programming style. ...

Typing Javascript

This one thing I never said ever - “once you type, you cannot un-type”. Yep, I make up words and compete on how to level up in my eating my own words. Even if I allegedly uttered those words (which are totally unoriginal anyway), I happily don’t abide by them. I continue to use Javascript without types with all fervour (and have had a stint with typeless / loosely-typed scripting languages). ...

Switch from if/else hell

Imagine you are in need of a complex if/then routine. No, not the below.. const smart = true; if (smart) console.log("I am smart"); else console.log("I am not so smart"); .. but more of.. function sum(a, b) { let smartMessage; if (a + b <= 0) smartMessage = "Negative numbers are not known and cannot be computed."; else if (a + b < 10) smartMessage = "Less than 10? X, Really?"; else if (a + b < 50) smartMessage = "You could have just returned L"; else if (a + b < 100) smartMessage = "You are nearing the big C"; else if (a + b < 500) smartMessage = "You are nearing the bigger D"; else smartMessage = "It is all about M from here on"; return smartMessage; } console.log(sum(200, 2)); The above program works, and shows its smartness through the message. But there obviously should be a better way than to write a thousand if’s and but’s. ...

Reverse a String in Javascript

Oh.. why? Why should we work on theoritical algo problems when we could develop the next Instagram or Salesforce.com? Because, son - you have to learn the different paths to glory. Why take the longer path when it can be shorter? That aside: let us look at multiple ways of reversing a string in Javascript. The best and easiest way Convert to array and back. const txt = "abcxyz"; console.log(txt.split("").reverse().join("")); Prove that I know ‘modern’ functions Aka - use reducer to reverse. ...

Should you use ternary operator?

Yes. Now, go back to work.. may be? What the heck is this? I am sure you used something called if/else? const sum = a + b; let result; if (sum > 100) result = "too high"; else result = "just right"; Instead of the “elaborate” syntax, we can just shorthand it. const result = a + b > 100 ? "too high" : "just right"; So, should you use it? Emm.. it depends. ...

Javascript Frontend Frameworks - A Quick Glance

Frameworks in Javasripts make your life easy. A Javascript frontend framework encapsulates libraries, code structure, tools and utilities. What a framework contains is left to the philosophy of that framework and the community built around the framework. Javascript world today has numerous frameworks that are company or community maintained. We will delve further in that topic, but first.. A bit of History Web developers did not have an exciting life until mid 2000s. That is when Google showed the world what Javascript could do with Gmail and other Google applications. ...

Semicolon is Safer

Javascript has and always have people who fight about anything and everything. I am always on the one side or the other, trying to raise the pitch whenever I can. After all, what is life if there is no stupidity? We should get annoyed, irritated, angered and humiliated at every instance possible. But, this topic is different. This topic is about using a semicolon in Javascript. And, there is only one way shown by God or your belief system. ...

Great Resources to Learn Javascript

I have been on and off Javascript for a long time. It took me till 2018 to get back on track. I am not quite a beginner and no where near an expert, and can write BS till eternity. That makes me the best qualified person to enlighten you about how to ideally learn Javascript. I divide this into three categories of learning. My order of preference - Do stuff while you read, watch or listen: learn, break, repeat cycle. You have to get to this to maximise learning. ...