Interview Questions for the Javascript Developer: Postfix & Prefix Operators, Truthy & Falsy Values, & == vs. ===
Tags: javascript, webdev, career, beginners
Published: 2019-06-15 09:57:37

In the last article, we looked at *hoisting*, *prototypal inheritance*, and the differences between an *attribute* and a *property*. You can find that article [here](https://dev.to/bcaruthers/interview-questions-for-the-javascript-developer-hoisting-prototypal-inheritance-and-attribute-vs-property-4d2b). Today, we will continue to prepare for an interview by looking at the differences between *postfix* and *prefix increment/decrement operators*, *truthy* and *falsy values*, and *equality* vs. *identity operators*.

### Postfix & Prefix Increment/Decrement Operators

![Mailboxes on a brick wall image](https://res.cloudinary.com/dqejlzsb4/image/upload/v1560575775/kristina-tripkovic-602495-unsplash.jpg)

Postfix (`x++`/`x--`) and prefix (`++x`/`--x`) increment/decrement operators are used to either increase or decrease a variable by 1 and return that value. Most of us are familiar with the postfix increment operator `i++` found in a For Loop. So if they both increase or decrease a variable by one, what's the difference?
 
If it is used postfix (`x++`/`x--`), then it returns the value *before* incrementing or decrementing the variable. Check out this example:

{% replit @bcaruthers/Postfix-example %}

If it is used prefix (`++x`/`--x`), it returns the value *after* incrementing or decrementing the variable. Check out this example:

{% replit @bcaruthers/Prefix-example %}


### Truthy & Falsy Values

![Bowl of candy hearts image](https://res.cloudinary.com/dqejlzsb4/image/upload/v1560576098/obi-onyeador-559118-unsplash.jpg)

Truthy and falsy are funny sounding words. But, what are they? JavaScript uses type coercion, in a boolean context, on all values. When a value is evaluated in a boolean context, if the value is true it is called a truthy and if it is false it is called a falsy. All values are considered truthy, except for `false`, `0`, empty strings (single quotes, double quotes, and template literals), `null`, `undefined`, and `NaN`, which are all falsy.

### Equality vs. Identity Operators

![Equal stairs but diffrent colors image](https://res.cloudinary.com/dqejlzsb4/image/upload/v1560577676/greg-jeanneau-145138-unsplash.jpg)

So what's the difference between `==` and `===`? The *equality operator* (`==`) compares two values for equality after any necessary type conversion. So `1 == "1"` would return `true`, just the same as `1 == 1` returns true. JavaScript converts the string `"1"` into a number and then compares it to the number `1`.

The *identity* or *strict equality operator* (`===`) compares two values for equality, but there is no type conversion. So the values have to be of an equal type also. So `1 === 1` would return `true`, whereas `1 === "1"` would return `false`.

I hope that this article has helped you to better understand postfix and prefix operators, truthy and falsy, and the equality and identity operators. I would like to thank all of my readers for the overwhelming support of my first article on [Dev.to](Dev.to). I would also like to thank my instructors, Jerome Hardaway, Brad Hankee, and Phil Tenteromano, over at [#Vets Who Code](https://vetswhocode.io/) for their training, support, and for pushing me to write articles. I wish you all the best of luck on your interviews and stay tuned for more articles in the series over the next few weeks.

###### *Photo Credits (in order of appearance):*

###### <a style="background-color:black;color:white;text-decoration:none;padding:4px 6px;font-family:-apple-system, BlinkMacSystemFont, &quot;San Francisco&quot;, &quot;Helvetica Neue&quot;, Helvetica, Ubuntu, Roboto, Noto, &quot;Segoe UI&quot;, Arial, sans-serif;font-size:12px;font-weight:bold;line-height:1.2;display:inline-block;border-radius:3px" href="https://unsplash.com/@tinamosquito?utm_medium=referral&amp;utm_campaign=photographer-credit&amp;utm_content=creditBadge" target="_blank" rel="noopener noreferrer" title="Download free do whatever you want high-resolution photos from Kristina Tripkovic"><span style="display:inline-block;padding:2px 3px"><svg xmlns="http://www.w3.org/2000/svg" style="height:12px;width:auto;position:relative;vertical-align:middle;top:-2px;fill:white" viewBox="0 0 32 32"<path d="M10 9V0h12v9H10zm12 5h10v18H0V14h10v9h12v-9z"></path></svg></span><span style="display:inline-block;padding:2px 3px">Kristina Tripkovic</span></a>

###### <a style="background-color:black;color:white;text-decoration:none;padding:4px 6px;font-family:-apple-system, BlinkMacSystemFont, &quot;San Francisco&quot;, &quot;Helvetica Neue&quot;, Helvetica, Ubuntu, Roboto, Noto, &quot;Segoe UI&quot;, Arial, sans-serif;font-size:12px;font-weight:bold;line-height:1.2;display:inline-block;border-radius:3px" href="https://unsplash.com/@thenewmalcolm?utm_medium=referral&amp;utm_campaign=photographer-credit&amp;utm_content=creditBadge" target="_blank" rel="noopener noreferrer" title="Download free do whatever you want high-resolution photos from Obi Onyeador"><span style="display:inline-block;padding:2px 3px"><svg xmlns="http://www.w3.org/2000/svg" style="height:12px;width:auto;position:relative;vertical-align:middle;top:-2px;fill:white" viewBox="0 0 32 32"><path d="M10 9V0h12v9H10zm12 5h10v18H0V14h10v9h12v-9z"></path></svg></span><span style="display:inline-block;padding:2px 3px">Obi Onyeador</span></a>

###### <a style="background-color:black;color:white;text-decoration:none;padding:4px 6px;font-family:-apple-system, BlinkMacSystemFont, &quot;San Francisco&quot;, &quot;Helvetica Neue&quot;, Helvetica, Ubuntu, Roboto, Noto, &quot;Segoe UI&quot;, Arial, sans-serif;font-size:12px;font-weight:bold;line-height:1.2;display:inline-block;border-radius:3px" href="https://unsplash.com/@gregjeanneau?utm_medium=referral&amp;utm_campaign=photographer-credit&amp;utm_content=creditBadge" target="_blank" rel="noopener noreferrer" title="Download free do whatever you want high-resolution photos from Greg Jeanneau"><span style="display:inline-block;padding:2px 3px"><svg xmlns="http://www.w3.org/2000/svg" style="height:12px;width:auto;position:relative;vertical-align:middle;top:-2px;fill:white" viewBox="0 0 32 32"><path d="M10 9V0h12v9H10zm12 5h10v18H0V14h10v9h12v-9z"></path></svg></span><span style="display:inline-block;padding:2px 3px">Greg Jeanneau</span></a>