We will do some basic JavaScript coding via the Chrome DevTools console; specifically, just calling a built-in the alert() function to display an alert.
alert('Packt publishing loves open source. You want to write? See http://authors.packtpub.com');alert box pop-up with the text 'Packt publishing loves open source. You want to write? See http://authors.packtpub.com' (or whatever string you passed into the alert function). After the code is executed, it will appear in the log above the input line:
We've just executed some JavaScript code without having to edit and save any files. Although we did a simple alert, we are really not limited by what we can do. Anything that we can save in a JavaScript file, we can also enter in the Console.
You'll also notice that the same code that we typed in appeared in the log area. We'll also get an error message if any errors occur in the code—go ahead and try it! Instead of typing alert('My alert'); type something like fakealert('Boom');. This will give you a reference error, since nowhere is the fakealert()function defined —alert(); on the contrary, it is a built-in function, so we can call it from any page.
That's pretty much all there is to it! The rest just builds on these principles. Let's go ahead and do just one more thing, something that is slightly more involved, before jumping into manipulating an OpenLayers page.