Each of these properties of the language has interesting and fundamental implications for how we design, author, and reason about our code. In this part, we will explore each of these concepts, what they mean, and how we can use them to our advantage.
Around 2005, the web industry started to seriously explore and utilize a
paradigm known as
During this time, there were still many quirks and inconsistencies across
browsers and their implementations of web languages. With a quickly-progressing
I hope that this part will help set a foundation of understanding for your own exploration of this beautiful language and the capabilities it provides. Your expertise, of course, will come only in time with its mindful use and application.
In the code samples shown throughout this part, we will assume the existence of
a function called
log(), which takes any number of arguments and simply prints
each one (or a string representation of each one) separated by spaces. We will
use this in some cases to inspect the values of variables as code is executed.
Logged or returned values may be shown in code comments (
//) beside the line
on which a value is returned, or shown in a virtual “console” separate from the
log() function is actually available to use in your own programs as
console.log(), but here I use a shorthand for brevity.)
<!DOCTYPE html> <html> <head> <!-- Inline script: --> <script> let foo = 'Hello, browser.'; </script> <!-- External script: --> <script src="/url/path/to/script.js"></script> </head> <body> ... <script> // script elements can also be included // anywhere in the body of the document </script> </body> </html>
Most modern browsers also have developer tools with “scratchpad” and console features that let you write scripts in the browser itself and execute them in the context of the currently-open page. See:
Follow the instructions on nodejs.org to install the Node runtime for your system.
With Node installed, you can execute scripts from your system’s terminal:
// myscript.js console.log('Hello, node!');
$ node myscript.js Hello, node!