Notes on Jest, JavaScript Testing

Jest is from Facebook, it comes pre-installed in Create React App. It’s a good idea to install Jest globally since I will be using it from now on. Or install as a dev dependency: Run it with npm test by adding jest –watchAll in the package.json file. 3 ways to add test files: Put all the test files in __tests__ directory within the project folder Add files with .test.js Add files with .spec.js I like to add .spec.js inside each of my React component files. Each test per component stays on their component folder. For tesing general JavaScript, I will …

Read More

Binary Search Algorithm in JavaScript

Binary Search algorithm cuts the list in half to find the given item. Here I will be implementing binary search algorithm in JavaScript. Pseudo code: Create a variable min, set it to 0 Create a variable max, set it to array length – 1 Create a variable guess While min is less than or equal max, keep going Add min and max and divided them by 2; make it an integer if the target value equals the value in the index of guess, return the guessed index If the guess is higher than the target value, set max to guess …

Read More

JavaScript Closure Quickly Explained

A closure happens when one function is inside another function, and the inner function wants to access a variable which belongs to the outer function. In JavaScript every function creates its own scope. We may not realize it just by looking at the code, it will help if we visualize it like this: The floor is like the main function scope or the global scope. Every time you create a new function, it will be like a bucket. All the variables you create inside that bucket (function) will only be accessible within that bucket only. You can create a function …

Read More

Specializing in JavaScript

For the last few weeks I have taken a deep dive into the JavaScript programming language. Earlier this year I decided to work with Node.js so that I can work on just one language for the front end and the back. I am now going in deep with JS. It’s fun. I am following this collection of 33 Concepts in JS which is really helping me a LOT. I am tackling about one concept a day. One thing leads to another and I am spending most of my YouTube hours watching JS related videos and reading articles. Staying focused in one …

Read More

Why I am not a Fanboy of JavaScript

JavaScript, I like it, I love to build things with it, but I am not a fanboy. JS is the de facto language of the web. The web browsers only understands JavaScript. For this reason, web developers all around the globe has to learn this language. I chose Node.js to build the backend of my web application, just so that I can use a single language to build both the front and the back. I am not a fanboy of this language, and neither should you. In fact you should not be a fanboy of any given language, framework or …

Read More

Things I Learned While Building a Personal Project

Last week I ran into a real world problem. It’s hard to keep track of my washed and dirty clothes. I have no idea how long it’s been since last wash. So I needed to track them by making a list and counting the dates. The first idea is obviously writing them down on paper, but then I thought why not use my JavaScript skills to build an app to track it? The initial idea: It’s a one page app with a To-Do list kind of functionality. I want to be able to add and remove items. In this context, …

Read More