Introduction

In this lesson, we will look at what truthy and falsy values are, and then examine query strings and GET requests.

Truthy and falsy values

Each value in JavaScript has a Boolean value associated with it, known as truthy or falsy.

The following values are falsy:

  • false
  • 0 - the number zero
  • ””, ‘’ or - empty strings
  • null
  • undefined
  • Nan - Not a Number

Every other value is truthy.

If we are trying to check if a value exists (if it isn’t null or undefined) for example, we can do this:

if (someVariable) {
  console.log("someVariable exists");
}

rather than having to check for both null and undefined like this:

if (someValue !== null && someValue !== undefined) {
  console.log("someValue exists");
}

That applies to all the falsy values, so we can check that a variable’s value is not one of the falsy values by writing an if statement like this:

if (someVariable) {
  // someVariable has a truthy value
}

Scrimba video

Query strings

The query string is the part of the URL after the ?. It can be used to pass values around.

In the URL: https://youtube.com/watch?v=abcd1234
?v=abcd1234 is the query string. It has one parameter called v with a value of abcd1234.

Introduction to GET requests

One of the main things you will need to do as a front-end developer is connect to APIs.

In this introduction to GET requests we are going make a call to fetch data from an API.

This data will be in JSON format, and we can loop over it to create HTML like we have before with arrays of objects.

The following video takes another look at the same code.

Code from the video.


Lesson Task

Brief

There are practice questions in the master branch of this repo.

Attempt to answer the questions before checking them against the answers branch of the repo.

Tags: