Average

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Search Medium Write Sign up Sign In

Published in JavaScript in Plain English

fatfish
Oct 25 · 3 min read · Member-only
fatfish

Interviewer: Can “x !== x” Return True in 3.3K Followers

JavaScript? Hi friends, I am a front-end engineer from


Alibaba, let’s code happily together.

5 magical JavaScript knowledge points you may not know!


Follow

Recently I was asked a few strange interview questions. They are different
from the regular questions: these interview questions seem very easy, but
they test your thorough understanding of JavaScript. How many can you
answer correctly?

1. Can “x !== x” return true?


What should be the value of “x” to output “hello fatfish”?

Help Status Writers Blog Careers Privacy Terms About


Knowable
It’s amazing. Is there any value that is not equal to itself? However, there
is a value NaN in JavaScript, which is not equal to any value or even itself.

2. Can (!isNaN(x) && x !== x) return true?


Okay, when we filter out “NaN”, what other value can make a value not
equal to itself?
Maybe you know “object. Defineproperty”, which can help us solve this
problem.

3. How to make “x === x + 1”?


This question may not be easy, but as long as you know JavaScript, you will
know “The Number.MAX_SAFE_INTEGER constant represents the
maximum safe integer in JavaScript (²⁵³ — 1).”(From MDN)
So we can assign “x” any value greater than
“Number.MAX_SAFE_INTEGER”.

4. Can “x > x” be true?


I don’t want to read anymore, what kind of rubbish question is that?
Although it seems unlikely, how can a value be greater than itself?
However, we can use the “Symbol.toPrimitive” feature to complete the
question.

Wow, that’s amazing!

5. typeof x === ‘undefined’ && x.length > 0 ?


I have to admit that JavaScript is an amazing language. Besides undefined

itself, what other value can make typeof x === undefined” true?

The answer is document. All An HTMLAllCollection which contains every


element in the document (from MDN).

Finally
Thanks for reading. I am looking forward to your following and reading
more high-quality articles.

Interviewer: Can (a==1 && a==2 && a==3) ever evaluate to true in
JavaScript?
Yes, it can be true, and there are 6ways — amazing!
javascript.plainenglish.io

“I Lost a Job Opportunity Just Because of Promise.all”


An interview experience that made me so sad.
javascript.plainenglish.io

Interviewer: What Happened to “npm run xxx”?


A secret that most people don’t know.
javascript.plainenglish.io

It’s 2022, Don’t Abuse the Arrow Function Anymore


4 cases where you shouldn’t use arrow functions.
javascript.plainenglish.io

More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow
us on Twitter, LinkedIn, YouTube, and Discord. Interested in Growth Hacking?
Check out Circuit.

-- 1

More from JavaScript in Plain English Follow

New JavaScript and Web Development content every day. Follow to join 2.5M+
monthly readers.

Read more from JavaScript in Plain English

Recommended from Medium

Shishir Chandra Felix Harrison in Songkick Tech

Elasticsearch In A Nutshell Pa We’re so cutting edge: How we


added a React App to our Rails
project at Songkick

Aaarghhh Babylon.js

[Action required] Your RSS.app Share 3D Models with


Trial has Expired — Tue Jul 20 WebSockets Demo
2021

Citrusbug Technolas Eli Elad Elrom in Master React

Top Frontend Frameworks of Save React Component as


2020 for Web Development png, jpeg, or PDF

Nmeregini Vincent Jonathan Saring in Bits and Pieces

Understanding the Higher 9 Bootstrap UI Component


Order Component in React JS Libraries for React, Vue,
Angular in 2019
About Help Terms Privacy

You might also like