Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best ways to develop painlessly in Javascript on a local machine

I'm pretty new to workign with Javascript.

In most languages you can run the code quickly locally on your machine. From what I've seen, in JS you generally only use it via the browser, and so I've been uploading my code an viewing its effects in the browser. This has proven very tiresome. Also, if I mak one error, it seems like my JS/JQuery will just do NOTHING, instead of giving me a useful error, message, which is making it painfully slow to code in.

IS there some way to run JS locally to see that it is working as I go? And then only upload it to the web when I'm mostly done? What ways are there for me to do this? What ways aer there for me to unit test the Javascript locally? Say I have some JAML that should render as <p>HI</p>, how do I run this locally in a unit test?

Thanks for the help, Alex

EDIT:

Thanks for all the great suggestions. I'll have to take a bit of time and go through them to see which ones best help me in my situation.

like image 959
Alex Baranosky Avatar asked Aug 31 '10 23:08

Alex Baranosky


People also ask

Why is reading JavaScript so hard?

JavaScript is so hard to learn because it's an asynchronous programming language. It's also single-threaded, which means it uses its asynchronous nature in a radically different way than most other programming languages.

Which function should not be used to run JavaScript?

Avoid Using eval() In almost all cases, it should not be necessary to use it. Because it allows arbitrary code to be run, it also represents a security problem.

Why my JavaScript is not working?

On the web browser menu click on the "Edit" and select "Preferences". In the "Preferences" window select the "Security" tab. In the "Security" tab section "Web content" mark the "Enable JavaScript" checkbox. Click on the "Reload the current page" button of the web browser to refresh the page.


1 Answers

Since you're using jQuery, I assume that you actually want to manipulate the various elements on your page. So depending on your specific development enviroment, uploading it each time is probably the way to go anyway. If you can set up a dev enviroment on your local machine (not always possible) then go with that.

As an actual answer to your question, I suggest using Chrome's developer tools, it doesn't just have the console, but an element inspector, and a resource tracker (resource tracker is invaluable when working with JSON and AJAX, since invalid json will fail silently)

As far as I know, the firebug plugin for firefox (dont use it myself) has a similar feature set, so if you're more comfortable with that go with it.

Just remember, as a developer, your development (and debuggin) enviroment is just as important as the code that you are writing.

EDIT: Noticed that you mentioned unit testing. There are several unit testing frameworks out there for JS including one that integrates with firebug called FireUnit. Do a quick google search to find more if you want.

like image 171
Aatch Avatar answered Oct 22 '22 20:10

Aatch