Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
JavaScript from Beginner to Professional

You're reading from   JavaScript from Beginner to Professional Learn JavaScript quickly by building fun, interactive, and dynamic web apps, games, and pages

Arrow left icon
Product type Paperback
Published in Dec 2021
Publisher Packt
ISBN-13 9781800562523
Length 546 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (4):
Arrow left icon
Codestars By Rob Percival Codestars By Rob Percival
Author Profile Icon Codestars By Rob Percival
Codestars By Rob Percival
Laurence Svekis Laurence Svekis
Author Profile Icon Laurence Svekis
Laurence Svekis
Maaike van Putten Maaike van Putten
Author Profile Icon Maaike van Putten
Maaike van Putten
Rob Percival Rob Percival
Author Profile Icon Rob Percival
Rob Percival
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Getting Started with JavaScript FREE CHAPTER 2. JavaScript Essentials 3. JavaScript Multiple Values 4. Logic Statements 5. Loops 6. Functions 7. Classes 8. Built-In JavaScript Methods 9. The Document Object Model 10. Dynamic Element Manipulation Using the DOM 11. Interactive Content and Event Listeners 12. Intermediate JavaScript 13. Concurrency 14. HTML5, Canvas, and JavaScript 15. Next Steps 16. Other Books You May Enjoy
17. Index
Appendix – Practice Exercise, Project, and Self-Check Quiz Answers

Using the browser console

You may have seen this already, or not, but web browsers have a built-in option to see the code that makes the web page you are on possible. If you hit F12 on a Windows computer while you are in the web browser, or you right-click and select Inspect on macOS systems, you will see a screen appear, similar to the one in the following screenshot.

It might work slightly differently on your browser on your machine, but right-clicking and selecting Inspect generally does the trick:

Figure 1.1: Browser console on the Packt website

This screenshot contains multiple tabs at the top. We are now looking at the element tabs, which contain all the HTML and CSS (remember those?). If you click on the console tab, you will find at the bottom of the panel a place where you can insert some code directly. You may see some warnings or error messages in this tab. This is not uncommon, and don't worry about it if the page is working.

The console is used by developers to log what is going on and do any debugging. Debugging is finding the problem when an application is not displaying the desired behavior. The console gives some insights as to what is happening if you log sensible messages. This is actually the first command we are going to learn:

console.log("Hello world!");

If you click on this console tab, enter the first JavaScript code above, and then hit Enter, this will show you the output of your code therein. It will look like the following screenshot:

Figure 1.2: JavaScript in the browser console

You will be working with the console.log() statement a lot throughout the book in your code to test your code snippets and see the results. There are also other console methods, such as console.table(), that create a table when the inputted data can be presented as a table. Another console method is console.error(), which will log the inputted data, but with a styling that draws attention to the fact that it's an error.

Practice exercise 1.1

Working with the console:

  1. Open the browser console, type 4 + 10, and press Enter. What do you see as the response?
  2. Use the console.log() syntax, placing a value within the rounded brackets. Try entering your name with quotes around it (this is to indicate the fact that it's a text string—we'll get to this in the next chapter).
You have been reading a chapter from
JavaScript from Beginner to Professional
Published in: Dec 2021
Publisher: Packt
ISBN-13: 9781800562523
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime