Search icon CANCEL
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 and JSON Essentials

You're reading from   JavaScript and JSON Essentials If you fancy a less verbose data format than CSV or XML, then JSON could be for you. This tutorial will teach you about using JSON with JavaScript for effective local storage or Internet transfers.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher Packt
ISBN-13 9781783286034
Length 120 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sai S Sriparasa Sai S Sriparasa
Author Profile Icon Sai S Sriparasa
Sai S Sriparasa
Arrow right icon
View More author details
Toc

Chapter 1. JavaScript Basics

JavaScript, which was introduced as LiveScript by Netscape Communications Corp, has grown leaps and bounds in the last few years. JavaScript was originally developed to make web pages more interactive, and control the behavior of the page. JavaScript programs are commonly embedded inside an HTML file. HTML is a markup language, and does not manipulate the behavior of a page once its loaded. Using JavaScript, web developers can set rules and verify if the rules were followed, avoiding any remote server resources for input validation or complex number crunching. Today JavaScript is not just used for basic input validation; it is used to access the browser's Document object, to make asynchronous calls to the web server, and to develop end-to-end web applications using software platforms such as Node.JS, which is powered by Google's v8 JavaScript engine.

JavaScript is considered to be one of the three building blocks that are required to create interactive web pages; it is the only programming language in the trinity that is HTML, CSS, and JavaScript. JavaScript is a case sensitive and a space insensitive language, unlike Python and Ruby. A JavaScript program is a collection of statements and those statements have to be included inside the <script>> tags.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

JavaScript has to be invoked from another application such as a browser. Browsers have a built-in JavaScript engine that interprets and executes the JavaScript on the webpage. The interpretation of JavaScript is from top to bottom and goes from left to right. SpiderMonkey and Rhino are few of the early JavaScript engines that were implemented by different browsers, such as Netscape Navigator and Mozilla Firefox.

Next is our simple Hello World program; the JavaScript program is in between the <script> tags in the head section. The script tags can either be added to the head tag or to the body tag. As JavaScript is not non-blocking, the scripts hold the page until they are loaded. It is common to see the scripts being loaded at the end; this would work if there were no dependencies to other files or elements. One such example of a dependency would be a library that is used from a different location. We will be looking at a lot of these examples in the later chapters. We will be discussing the role of Unobtrusive JavaScript at a later point. For our Hello World program, use a text editor of your choice, and save this program with an HTML extension. Load the file in a web browser, and a pop-up box with the text Hello World! should be loaded on the page.

The following code snippet is the first_script.html file:

The output is as follows:

You have been reading a chapter from
JavaScript and JSON Essentials
Published in: Oct 2013
Publisher: Packt
ISBN-13: 9781783286034
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 £16.99/month. Cancel anytime