Category: Programming

Falsy vs. Nullish Values in JavaScript

Falsy vs. Nullish Values in JavaScript

This is a quick summary on Falsy and Nullish values in JavaScript. JavaScript has 8 falsy values, and 2 nullish values. The two nullish values are also falsy, but the rest of the falsy values are not nullish.

Falsy Values

A falsy value is something that is considered as false when used in a boolean context. JavaScript uses Type Coercion to convert non-boolean values in boolean contexts (such as a conditional, or a loop) into boolean form. There are 8 falsy values:

ValueDescription
falseThe keyword false
0Number 0
-0Negative number 0
0n0 in BigInt
‘’, “”Empty string
nullPrimitive null – no value
undefinedPrimitive undefined
NaNNot a Number
Table 1: Falsy values in JavaScript

Nullish Values

The two primitives null and undefined are known as nullish. Put simply, it means that they don’t have any value. They get converted to false via Type Coercion in a boolean context.

Venn diagram of Falsy and Nullish values in JavaScript.
Figure 1: Venn diagram of Falsy and Nullish values in JavaScript.

By above definitions, we see that nullish values are also falsy.

GSoC 2017 – Week 6

GSoC 2017 – Week 6

It’s the end of the 6th week and I’m happy to bring some UI to the mix. Up until now we’ve been working with the stuff that was made before. But now it’s time for new enhancements. The first part of it is enhancing the pre-theater workflow.

Along that line, we discussed what data need to be collected before a procedure, last week. I asked the community what they considered necessary, while making my own suggestions. Just as expected, there are already some implementations of data collection of a surgery.

One example was a post-op form used by a Partners In Health member. She provided screenshots of the form which they used to collect data about the procedure after it took place. It included fields to record the surgical team involved, the location of the procedure, anesthetics, complications etc. They were not collecting any data before the procedure, so they used the same form to record pre-operative diagnoses as well.

Read More Read More

GSoC 2017 – Week 3

GSoC 2017 – Week 3

This week I was mostly working in checking the functionality of the system, looking at UI elements, following method calls related to surgery CRUD operations etc.

I found a few cases where a surgery validation failed when trying to enter a  emergency procedure. The problem was that the surgery associated with the emergency procedure was not properly initialized, which caused it to fail validation. A few breakpoints with IntelliJ IDEA helped to solve that. Special thanks to Gayan Weerakutti for helping me to setup debugging.

Then there were some UI elements that didn’t appear properly. Checked through files and came across a set of JSON files that were apparently used for configuring the UI, but I couldn’t understand exactly how they interacted with the other files. They aren’t imported anywhere. I’m guessing the OpenMRS classloader is specially configured to look at the path they exist and read them if they’re there.

I’ll update this post with more info in a bit.

GSoC 2017 – Week 2

GSoC 2017 – Week 2

I’m gonna keep this one short, at least for now. You know the reason.

Last week, we decided to replace the Joda Time library with java.time and ThreeTen-Extra library. And that’s exactly what I did this week.

The Migration

There were 3 steps to what I did.

  1. Identifying the replacement classes.
  2. Understanding the class structure to start the migration from the base classes.
  3. Figuring out the best match for a given instance of replacement.

It might not look like much, but there was quite a bit of work once I got into it. I had already started off the replacement without much thought in the previous week. But as I later realized, it’s better to first look exactly where and how the base classes are used later.

Read More Read More

GSoC 2017 – Operation Theater Module Workflow Enhancements

GSoC 2017 – Operation Theater Module Workflow Enhancements

This is the official blog for my Google Summer of Code 2017 project. I am going to be working for OpenMRS, an open source project that supports healthcare delivery around the world. It feels great to have been awarded this opportunity, thank you @Team OpenMRS! 😁

My project is to work on the Operation theater module, which has been made as part of GSoC 2014. It’s used to schedule surgeries and other operation theater activities in multiple theaters. The module was written for an older OpenMRS version, so my first task is to migrate it to the latest platform.

Read More Read More

Materialize CSS Autocomplete with AJAX

Materialize CSS Autocomplete with AJAX

At the time of writing this article, Materialize CSS framework’s Autocomplete widget didn’t work properly with AJAX calls. So I gave it a go myself.

Ideally, the autocomplete widget should have the following features.

  • AJAX calls must be made only after a certain minimum number of characters are entered.
  • Requests must not be sent until the user stops typing into the box. This means setting a reasonable timeout to check end of typing.
  • If a request is already on its way when the user enters more characters, the existing request must be cancelled before sending a new one.
  • Clicking a result or outside the results list must close the list.
  • Certain keys should not trigger AJAX calls.
  • The results must be scrollable with arrow keys and selectable with Enter.

The code looks something like this. A few important things are explained below it.

Read More Read More