Atom
Atom's Cove

Atom's Cove

JavaScript 101: Getting Started with JavaScript

Photo by Gabriel Heinzer on Unsplash

JavaScript 101: Getting Started with JavaScript

In this first lesson, I will teach you the very basics of JavaScript. You will learn how it's run and how to use it.

Atom's photo
Atom
·May 10, 2022·

5 min read

Subscribe to my newsletter and never miss my upcoming articles

Table of contents

  • Introduction
  • What is JavaScript?
  • Why is JavaScript used?
  • What is a runtime?
  • Syntax
  • Conclusion

Introduction

Hello everyone! After seeing the success of my Python 101 course, I have decided to start a JavaScript course. I have been working 3 days on laying this course out for you neatly.

We will be covering all JavaScript essential topics in this course and beyond! So, what are we waiting for? Let's get started!

What is JavaScript?

JavaScript is a programming language which is one of the core technologies of the internet, alongside HTML and CSS. Over 97% of websites use JavaScript on the client-side of their website, often incorporating third-party libraries including React, Vue, Angular, etc.

Why is JavaScript used?

JavaScript is used by programmers to create dynamic and interactive web content like applications and browsers. Vanilla JavaScript can only be used inside a browser environment, but with the use of different runtimes such as Node.js (what we will be using) and Deno, we can use it outside a browser.

What is a runtime?

A runtime is not a language. It is a runtime which uses different browser engines such as Chrome's V8 and converts your JavaScript code into faster machine code which is then executed.

Node.js

Node.js is an asynchronous event-driven JavaScript runtime designed to built scalable network applications. - Node.js Website

The Node.js website describes itself perfectly. Node.js is a runtime built on top of Chrome's V8 engine, which allows it to execute JavaScript code and converts it to machine code.

With Node.js, you can run JavaScript outside a browser environment and use it like other languages such as C++, Java, Python, etc. Node.js and JS combined have the same functionality of all of those languages. Node.js preinstalls a package manager called npm which allows users to install modules. Other languages also have package managers. For example, Python uses PIP, Ruby has RubyGems, and Rust has Cargo.

Node.js is the most popular in the US. Over 6.3 million websites based in the US use it. Out of over 63,000 checked websites in the US, more than 37,000 completely run on Node. Massive corporations such as Google, Spotify, etc. run on Node.js.

So, after this large introduction, let's dive into JavaScript!

Syntax

Syntax are writing rules that you have to follow while writing code. For example, in English, you need to remember to have periods at the end of sentences, and you also need to remember to indent your line at the beginning of a new paragraph.

JavaScript's syntax defines two types of values:

  • Fixed values
  • Variable values

Fixed values are called literals and variable values are called variables.

Literals

The two most important syntax rules for fixed values are:

Numbers are written with or without decimals

5.25

1200

Strings are text, written with double or single quotes.

"atomdevelops"

'atomdevelops'

Variables

In programming, variables are used to store data values. JavaScript uses the keywords var, let, and const to declare variables.

Note: The keyword var isn't very used anymore after the introduction to newer ES versions.

An equal sign is used to assign values to variables. In the following example, x is defined as a variable. Then, x is assigned the value 5:

let x;
x = 6;

Note: Not all variable types allow you to reassign variables. This same example won't work for the const variable, as it stands for constants. Variables will be explained more thoroughly in the next lesson.

Operators

JavaScript uses arithmetic operators (+ - * /) to compute values:

console.log(5 + 10 * 10)

As we talked about earlier, JavaScript also uses an assignment operator (=) to assign values to variables.

Comments

Like other languages, not all JavaScript statements are "executed." Code after double slashes // or between /* and */ is treated as a comment. Comments are ignored, and therefore will not be executed.

let x = 5; // This line IS executed.

// x += 1; This line is NOT executed.

Identifiers/Names

Identifiers are JavaScript names. Identifiers are used to name variables, keywords, and functions. The rules for legal names are the same in most programming languages. A JavaScript name must begin with:

  • A letter (A-Z or a-z)
  • A dollar sign ($)
  • Or an underscore (_)

Subsequent characters may be letters, digits, underscores, or dollar signs.

Note: Numbers are not allowed as the first character in identifiers.

Case Sensitivity

Like all languages, JavaScript is case-sensitive. This means that uppercase characters and lowercase characters do not mean the same thing. For example, ABC and abc are two entirely different variables:

let ABC = "ABC";
let abc = "abc";

console.log(ABC); // --> returns "ABC"
console.log(abc); // --> returns "abc"

Camel Case

Programmers have used many ways of joining multiple words into one variable name:

  • Hyphens:
    • first-name, last-name, date-of-birth
  • Underscore:
    • first_name, last_name, date_of_birth
  • Lower Camel Case:
    • firstName, lastName, dateOfBirth

I recommend using camel case as it's widely used and the most comfortable (it is also prettier).

Conclusion

That's the end of my first JavaScript lesson! Don't worry, there will be more. Like the Python course, I will be assigning homework sometimes for other lessons. This is the introductory lesson, so there won't be any.

Always know, the homework assignments are only there to improve your skills and to test what you know. They are not required.

Other than that, have a wonderful day and see you later!

 
Share this