5 ms·
This is worth getting your head around just for the console. <this post is partially for those of you who are, like me, relatively new to javascript. If you'r
by blhack 14y ago
This is worth getting your head around just for the console.
<this post is partially for those of you who are, like me, relatively new to javascript. If you're one of the demigods that works at twitter/facebook, go ahead and ignore this>
I've been transitioning all of my projects from python cgi scripts (yuck), to shtml files, javascript clients, and APIs that run on node.js.
For somebody like me, that has been writing python+cgi for the last 5 years, diving into javascript was daunting. Terrifying even.
Console made this a lot, lot, lot easier. In javascript, you can call
console.log("thing")
and it will print it out to the console (again, this is obvious if you're done any JS development, I'm sure).
But that isn't all...
Suppose that I'm working with an object called map_pins. In the javascript console, I can just type:
map_pins;
and it will print out the object for me in a tree that I can traverse by clicking the little sideways triangles.
Very, very nice.
I can also interact with my javascript functions from the console. If I have a function called update_bounds(), I can force it to fire from the console by just typing:
update_bounds()
This is really, really nice. Before I discovered this, my javacsript was full of alert("I made it to this without crashing");
It was awful.
If you're learning JS and OP's article looks over your head, at least take the console away from it.
- jtaby 14y agoThanks for the comment. Was there anything specific you could point me to that you felt was above your head? I'd love to do a follow-up with more introductory material.
- philwelch 14y agoThe console is great. It's basically a REPL for Javascript.
- markkanof 14y agoAlso, don't forget the step through debugger. It's such a time saver to be able to set a couple of break points and then when they are hit you can hover your mouse over different variables and see a tool tip that shows the contents of that variable.
- carbocation 14y agoA great post for beginners. Also, beware of the fact that console.log() doesn't always print out the value of the object at the time it is logged; it can print out the value of the object at some time after the fact, leading you to believe there is a bug in your code when there is in fact none. See also: https://bugs.webkit.org/show_bug.cgi?id=35801 https://bugs.webkit.org/show_bug.cgi?id=35801 http://code.google.com/p/chromium/issues/detail?id=50316 http://code.google.com/p/chromium/issues/detail?id=50316 http://stackoverflow.com/a/8249333/199475 http://stackoverflow.com/a/8249333/199475
- TeMPOraL 14y agoIt's worth to note that this concept has a name - Read-Eval Print Loop, or REPL, and is present in several good languages. It changes the way people think about programming, making it much more interactive. If one didn't encounter this concept before, it's worth to take a look at it.