JS Test #1: Type conversion in JavaScript

coderslang

Coderslang: Become a Software Engineer

Posted on February 1, 2021

JS Test #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.

Every day in February I'm going to post a new JS test here on Dev.to. Follow, like, comment if it's something you're interested in.

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

Learn Full Stack JavaScript

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
coderslang
Coderslang: Become a Software Engineer

Posted on February 1, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Challenge #17 - Sum of Unique Elements.
programming Challenge #17 - Sum of Unique Elements.

October 5, 2021

JS Test #1: Type conversion in JavaScript
programming JS Test #1: Type conversion in JavaScript

February 1, 2021

ยฉ TheLazy.dev

About