• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javascript interview riddle

 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..."
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic