Hey guys, I was just wondering if I could pick some of your brains for a few moments. I'm trying to further advance my skill set in the funky world of Javascript, and I'm trying to evolve my coding though the use of best practices, good planning, clean coding, etc and I have just finished reading Douglas Crockford's book java script: The good Parts and am starting into John Resig's book the Javascript Ninja and has a few quick questions for ya. Thanks in advance for your time and consideration. 1) From the John Resig's website...http://ejohn.org/apps/learn/#10How would you say line 2?
function yell(n){ return n > 0 ? yell(n-1) + "a" : "hiy";}assert(yell(4)=="hiyaaaa", "Calling the function by itself comes naturally.");
2) In Douglas Crockford book, java script: The Good Parts, he refers to the operators === and !== as alternatives to == and !=.
Does that mean that is the only applicable situations for those operators, is when comparing the above values? While we're on the subject, how would you define type coercion?3) Also, he suggests these shorthand methods:instead of (foo != 0), use (foo)
does that mean if foo has a value of anything (number, boolean, string) then you can just use (foo) and that resolves to true, if foo != 0?
instead of (foo == 0) use (!foo)
does this only apply when using numbers, or would this apply to false or an empty string as the value of foo? 3) Also, Douglas Crockford suggests against using ++ and -–. Would the appropriate alternative to say something like
(for i = 0; i <= 10; i++)
be
(for i = 0; i <= 10; i+=1)?
Thanks again for reading through this, I'm open to all your thoughts, comments, or suggestions. Does anyone have any recommendations on good books that better promote good coding practices, or good habits for developing code structure, scalability, employing DRY techniques, etc?Peace, have a good one!