• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Javascript interview riddle  RSS feed

 
Bartender
Posts: 1120
38
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recently I came across this question on twitter:

"Javascript expression (a==1 && a==2 && a==3) could ever evaluate to true ?"

The answer was clever and elegant - and yes, definitely above my knowledge of JS  

I thought it would be nice to propose the same riddle here...
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Precede your code with the following:



This is a reasonably well-known example of why you shouldn't redefine built-in functions in JavaScript. Don't do stuff like this.
 
Marshal
Posts: 64107
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched for it and found two other solutions on SO. One is to define the three variables with different characters all looking like a but only one is '\u0061'.
The other is to append characters which look like spaces but aren't to the a.
There was a solution similar to CM's on SO, too.

Several people gave a better answer still, “Don't take a job there.”
 
Claude Moore
Bartender
Posts: 1120
38
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:
Several people gave a better answer still, “Don't take a job there.”



Well, a riddle is a riddle after all...I suppose that  no one in real life would write such a tricky code !
 
Marshal
Posts: 67256
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Several people gave a better answer still, “Don't take a job there.”



Yup, for me that would be "just walk away" level nonsense.

Just as bad as "so there's this pirate that wants the gold rope..."
 
Master Rancher
Posts: 3179
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... with a wife and a couple of kids to feed, plus a mortgage to pay, "crying with the wolves" comes to mind.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!