## Saturday, February 02, 2013

### Are You a JavaScript Guru? Try This Test

Think you know JavaScript? Really? Are you sure? Try the following quick quiz. Guess what each expression evaluates to. (Answers given at the end.)

1. ++Math.PI
2. (0.1 + 0.2) + 0.3 == 0.1 + (0.2 + 0.3)
3. typeof NaN
4. typeof typeof undefined
5. a = {null:null}; typeof a.null;
6. a = "5"; b = "2"; c = a * b;
7. a = "5"; b = 2; c = a+++b;
8. isNaN(1/null)
9. (16).toString(16)
10. 016 * 2
11. ~null
12. "ab c".match(/\b\w\b/)

1. 4.141592653589793
2. false
3. "number"
4. "string"
5. "object"
6. 10
7. 7
8. false
9. "10"
10. 28
11. -1
12. [ "c" ]

For people who work with JavaScript more than occasionally, score as follows:

12: MASTER OF THE KNOWN UNIVERSE
10 - 11: SAVANT
8 - 9: EXPERT
5 - 7: KNOWLEDGEABLE
< 5: RUSTY

NOTES

The answer to No. 2 is the same for JavaScript as for Java (or any other language that uses IEEE 754 floating point numbers), and it's one reason why you shouldn't use floating point arithmetic in any serious application involving monetary values. There's an interesting overview here.

No. 6: In an arithmetic expression involving multiplication, division, and/or subtraction, if the expression contains one or more strings, the interpreter will try to cast the strings to numbers first. If the arithmetic expression involves addition, however, all terms will be cast to strings.

No. 7: What you've got here is "a, post-incremented, plus b," not "a plus pre-incremented b."

No. 9: toString( ) takes a numeric argument (optionally, of course). An argument of "16" means base-16, hence the returned string is a hex representation of 16, which is "10." If you write .toString(2), you get a binary representation of the number, etc.

No. 10: 016 is octal notation for 14 decimal. Interestingly, though, the interpreter will treat "016" (in string form) as base-ten if you multiply it by one.

Don't feel bad if you didn't do well on this quiz, because almost every question was a trick question (obviously), and let's face it, trick questions suck ass. OTOH, if you did well on a test that sucks, you should take full credit. It means you're no fool.

1. Hello, sir i would like to ask that what is the scope of java training, what all topics should be covered and it is kinda bothering me … and has anyone studies from this course http://www.wiziq.com/course/1779-core-and-advance-java-concepts of core and advance java online ?? or tell me any other guidance...
would really appreciate help… and Also i would like to thank for all the information you are providing on java concepts.

1. Tks very much for your post.

Avoid surprises — interviews need preparation. Some questions come up time and time again — usually about you, your experience and the job itself. We've gathered together the most common questions so you can get your preparation off to a flying start.

You also find all interview questions at link at the end of this post.

Best rgs

2. sainaen11:30 AM

And what's the catch with the last one? It's just a simple regexp as for me.

There must be some different score table for readers of your blog — got 9 and I'm not an expert in JavaScript at all. :)

1. Anonymous1:55 PM

Bullshit. I work as a JS programmer and didn't get half right.

2. Anonymous4:04 PM

same here, don't work with JS and I got 7, 8, 11, and 12 wrong (what's \b?)

3. Anonymous9:11 PM

1) In order to catch the "ab", one needs the \w to repeat, e.g., \w+. Otherwise, it looks for boundary, one letter, boundary.
2) In order to catch both "ab" and "c", one needs /../g flag.

4. sainaen12:49 AM

Phill,
Yeah, I know that. I'm saying it's just simple regexp rules as in any other language with regexps in it, not some kind of weird js magic as in expressions above.

Second Anonymous,
\b means word boundary (any symbol \W or start/end of line).

First Anonymous,
I think, it means you just haven't met this kind of stuff in your work. Yet. :)
Also, for me expert that's not a person who knows all tricks of language, but have a lot of experience in using it. And I don't.

3. Anonymous2:25 PM

Just my two cents: you should put a lot of whitespace between the questions and answers not to spoil it to someone accidentally.

4. Anonymous3:14 PM

some neat facts to be converted to flash cards ;)

5. The questions number 7 and 8 were the most tricky one for me. *Good* knowledge of at least one popular programming language is enough to answer questions 1, 2, 9, 10 I guess.

6. Anonymous5:54 PM

Most of these have absolutely no applicable use.

7. c = a+++b;

that is a good interview question... anyone who doesn't answer "why would anyone write stuff like that???" should never be hired.

8. I'm fairly new at JS, and I haven't run into any of those things yet. I've mostly programmed server side apps. Working with JS has been fun.

9. Anonymous4:09 AM

I've got déjà vu: http://www.planetpdf.com/developer/article.asp?ContentID=6337

10. This dual component configuration permits strikingly.com you to clean separate lots at the exact same time Popular Washer and Dryer Sets 2018 this means lengthy gone a minimum of in The Best Washer Dryers theory are the days of slackly stuffing your shades, Washing Machine and Dryer Reviews whites, as well as darks right into a single Website cold clean to conserve time.

11. I got diagnosed with hpv, i have be dealing with this mess for the past 7yrs. On till i got review online about natural cure people testifies how they got cured with natural treatment. And i order the treatment, after taking it for two weeks i totally got cured with herbal treatment. I'm recommending you diagnosis with hpv should get this treatment via; dronokunherbalcure@gmail.com or whatsapp call.. +2349064844957

12. I has suffered for Human papillomavirus HPV) for 2years, I was given some tablets at the hospital but I refused to take it, They said I have to be on it for life so I don't want take a drugs everyday for life. No point in taking medicine everyday when u won't get cure from it and I was advice to seek for natural herbal cure, after some time I found dr onokun is the most trustful herbalist that have herbs to cure wicked symptom's,I emailed dr onokun, for 2weeks been his patient he cured my (HPV) with his herbal. I only used his natural herbs for two weeks it was 100% cure. I'm not (HPV) patient anymore. I'm happy about it i finally got cured out of this mess been in my body for 2years. I also recommend you if you're living with (HPV) or herpes symptoms i also want you to be free contact dr onokun with the email attach to my post. Dronokunherbalcure@gmail.com

13. I'm 61 years old, I contracted hpv in 2011' I has be taking lot treatment for it and some months ago the wart stated coming out seriously, I used lot recommendation because there was lot warts around my anus and was so embarrassed. but today I'm totally happy I got the virus eliminated by using natural treatment from Dr Onokun herbal center after his treatment I got cured. all the warts went away' seriously believed Dr Onokun he have the cure for human papillomavirus because he has eliminated hpv been in my body since 2011, Dr Onokun make it possible for me. Here is Dr Onokun email to reach him: Dronokunherbalcure@gmail.com he is welled capable of curing terrible diseases.

14. 5 years ago I had warts, I was treated with some liquid applied to the warts they continued to grow and spread... The next 2 doctors did laser surgery to remove them. 1 year after the surgery, they grew back close to where the 1st ones were' so I was finally told it was hpv. I have had it for very long time, I contract it from my cheated boyfriend and I found out he was also infected and I end up the relationship between us. the warts was so embarrasses because it started spreading all over I have be dealing with this things for very long time the last treatment I take was About 2 years ago I applied natural treatment from Dr onokun herbal cure, a week after applying the treatment all the warts was gone. it's now 2 years and some months I don't have single wart or any symptoms of hpv. wow"" it's great, Dr onokun has finally cured me. Anyone living with hpv contact Dr onokun for natural treatment.