JavaScript
Brian Jenkins
JavaScript
Programming
A Step-by-Step Guide for Absolute Beginners
Brian Jenkins
Copyright 2019 by Brian Jenkins.
Edited and Published by
ATS Coding Academy and Amazon Kindle Publishing
All rights reserved.
The contents of this book may not be reproduced, duplicated or transmitted without the direct written permission of the author.
Under no circumstances will any legal responsibility or blame be held against the publisher for any reparation, damages, or monetary loss due to the information herein, either directly or indirectly.
Legal Notice:
You cannot amend, distribute, sell, use, quote or paraphrase any part or the content within this book without the consent of the author.
Disclaimer Notice:
Please note the information contained within this document is for educational and entertainment purposes only. No warranties of any kind are expressed or implied. Readers acknowledge that the author is not engaging in the rendering of legal, financial, medical or professional advice. Please consult a licensed professional before attempting any techniques outlined in this book.
By reading this document, the reader agrees that under no circumstances is the author responsible for any losses, direct or indirect, which are incurred as a result of the use of information contained within this document, including, but not limited to, errors, omissions, or inaccuracies.
Book Objectives
The following are the objectives of this book:
- To help you know how to get started with JavaScript programming.
- To help you understand the syntax and constructs that make up the JavaScript scripting language.
- To help you transition from a JavaScript Beginner to a Professional.
- To help you understand how to use JavaScript to improve the interactivity of your website applications.
Who this Book is for?
The author targets the following groups of people:
- Anybody who is a complete beginner to JavaScript programming or computer programming in general.
- Anybody in need of advancing their JavaScript programming skills.
- Professors, lecturers or tutors who are looking to find better ways to explain JavaScript to their students in the simplest and easiest way.
- Students and academicians, especially those focusing on computer programming and web development.
What do you need for this Book?
Make sure that you have the following:
- A text editor such as notepad.
- A modern web browser.
What is inside the book?
The book has been grouped into chapters, with each chapter exploring a different feature of the JavaScript scripting language. The author has provided JavaScript codes, each code performing a different task. Corresponding explanations have also been provided alongside each piece of code to help the reader understand the meaning of the various lines of the code. In addition to this, screenshots showing the output that each code should return have been given. The author has used a simple language to make it easy even for absolute beginners to understand.
About the Author
Brian Jenkins has a Ph.D. in computer science. He conducted coding research for magnetic recording systems and long-haul fiber optic communication systems. With two decades of experience teaching programming to newcomers, and one of the most talented IT specialists of his generation, Dr. Brian works as a Research Software Specialist and occasional as a bioinformatician.
Since 2015 Brian lives in Geneva, with his wife, and daughter. He is working on a series of books on computer programming and data science.
JavaScript is a language with more than its share of bad parts.
Douglas Crockford
Introduction
JavaScript is a powerful scripting language that every web developer should be familiar with. JavaScript has brought in many changes to the web development field. It has provided web developers with a way of making web pages more interactive. This is something most web visitors look for. If you know of validations, like checking whether a user enters correct details when filling forms, JavaScript is the best language to use for the implementation of such. It is one of the technologies of the WWW (World Wide Web). The good think with JavaScript is that it is supported by all modern web browsers. This means that you are not expected to get any special plugins to be able to run its scripts.
You can easily get started with writing and running JavaScript scripts because you only need basic elements like a text editor and a browser. Modern browsers come with the JavaScript Engine embedded; hence you dont need any other plugin to be able to run your scripts. The language also comes with many features and paradigms which you can rely on when writing your scripts. This book is an excellent guide for you on JavaScript programming. The author has discussed everything about JavaScript in a detailed manner. Enjoy reading!
To my wife and my daughter, you are the happiness of my days, and you are my truest love!
Contents
charAt()
Chapter 1- JavaScript Basics
What is JavaScript?
HTML was developed for content, CSS for presentation, but JavaScript was developed for interactivity. Originally, JavaScript was developed to add interactivity (such as animations and hovers) to small web pages, but it can now be used for nearly everything including large applications, games, and servers.
JavaScript programs are known as scripts . You can write JavaScript inside the HTML of a web page and it will be executed automated when the page is being loaded. The scripts are provided in plain text and executed as they are. They dont require a compilation or a special preparation so as to run. Today, we can execute JavaScript code on a browser, server or on a device with a JavaScript Engine . Initially, JavaScript was referred to as LiveScript because it made web pages alive. This name was later changed to JavaScript.
JavaScript is an object-based scripting language which can be interpreted by all modern-day browsers. This means that all browsers come with the JavaScript Engine. This has increased the popularity of JavaScript, making it the most popular scripting language today.
Environment Setup
To write, test and run your JavaScript code, you need the following:
You can write your JavaScript code using even a basic text editor such as Notepad. However, it is good for you to get an advanced text editor that will provide you with features such as syntax error highlighting, auto-completion, etc. Examples of such text editors include Visual Studio, Eclipse, Aptana, etc. These can help you with speedy development.
There are also online JavaScript editors that you can use for writing your scripts. A good example of this is jsfiddle.net.
For the case of the browser, you can install any type of browser depending on your preference. Examples of such browsers include Chrome, Internet Explorer, Safari, Firefox, Opera, etc. JavaScript can work on any browser running on any OS.
JavaScript Example
There are three places where we can place our JavaScript code. We can place the code within the body, within the head tag or in an external JavaScript file. Here is our first JavaScript example: