Skip to main content

Command Palette

Search for a command to run...

JS Interview Question #1: Type Conversion in JavaScript

Published
•1 min read•View as Markdown
JS Interview Question #1: Type Conversion in JavaScript

A couple of months back, I've started posting colorful JavaScript code snippets that you can use to check your JS skills on my blog. Every problem has the correct answer and explanation. But I strongly suggest you first try to solve it yourself.

As an experiment, I'm going to post a new JS Interview Question every day here on hashnode.

Follow, like, comment if you're interested in learning about the common interview questions that Junior devs almost always fail.

Let's go 🚀!

js-test What’s going to be printed to the console?

.

.

.

.

.

.

.

.

.

.

.

.

.

In the first line, we define the variable str and initialize it as a string with the value 1.

In the second line, there are two typecasts, first !str gives us false, and then +false converts boolean into a number 0.

Eventually, in the third line, the typeof operator looks up the current type of str which is number.

ANSWER: string number will be printed to the console

P.S. Share your love by pressing the LIKE button, pre-order a full book and Start Learning Full-Stack JavaScript!

JavaScript Interview Prep

Part 1 of 1

In this series I'm posting JS interview questions as colorful code snippets to help you prepare for your next JavaScript Interview. Each question has an explanation and a correct answer.