• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Javascript interview riddle  RSS feed

 
Ranch Hand
Posts: 982
9
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
Ranch Hand
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: 60155
188
  • 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 Hand
Posts: 982
9
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 !
 
Author and ninkuma
Marshal
Posts: 66806
168
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..."
 
Rancher
Posts: 2835
96
  • 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!