Eloquent JavasScript: Program Structure Exercises

I’m working on the ebook Eloquent JavaScript.

In Chapter 2 of the book there are some exercises, and the author prefaces them with, “If you are unsure how to test your solutions to the exercises, refer to the Introduction.” This provides a link to the beginning of the introduction but I am not clear on which part of the intro addresses “how to test your solutions to the exercises.”

There is a paragraph under the heading “Code, and what to do with it,” that states,“I recommend you try your solutions to exercises in an actual JavaScript interpreter. That way, you’ll get immediate feedback on whether what you are doing is working, and, I hope, you’ll be tempted to experiment and go beyond the exercises.” So maybe this is the part of the intro that addresses “how to test your solutions to the exercises.”

The author mentions a JS interpreter but he does not provide any links or examples of JS interpreters. When I Google “what is a Javascript interpreter,” I get lots of results about JavaScript engines, which is not helpful, since I’m trying to figure out what a JavaScript interpreter is, not a JavaScript engine.

Am I correct in thinking that “how to test your solutions to the exercises” corresponds to “I recommend you try your solutions to exercises in an actual JavaScript interpreter”? If so, can anyone explain what a JavaScript interpreter is and where to find one?


1 Like

It built into every browser. Easiest way is to console.log(yourValue);

1 Like

thanks for the reply.

I also read somewhere that I could activate the JS console in Google Chrome on my Mac with option + command + J. I didn’t realize it was as simple as using the browser.

thanks for the tip!

1 Like

To understand what JS interpreter is, you need to know how program is made.

Before JavaScript became popular, or rather “internet”, where C/C++ dominates.
Program is coded using a compiler. A compiler reads human written code and translate them to machine language aka executable program. This means that code written by human isn’t what machine reads, and it takes time for the compiler to make an executable file (.exe). The larger the program, the longer it takes.

An Interpreter is different from a compiler. Codes written to an interpreter are executed on the spot, no additional executable file is generated. The Interpreter isn’t a program, it is a piece of code embedded to your browser that allows your browser to understand statements like “console.log( “hello world” );”

For example below is a simple blank html page with a simple hello world code.
When the browser reads this page. It will run into the script tag which contains JS codes, which then the interpret will read and execute each line.

		<title>Basic Blank HTML Page</title>

		<script type="text/JavaScript">	
           //Your code goes here
           //you will need to press f12 to see your console output.
           console.log( "Hello World" ); 


From there, you can try all sorts of wonders you like.