Win a copy of Microservices in Action this week in the Web Services forum!
  • 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Javascript interview riddle  RSS feed

 
Ranch Foreman
Posts: 1026
24
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: 61799
193
  • 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
Ranch Foreman
Posts: 1026
24
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: 67164
169
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: 3010
105
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!