My Starting Point in Learning JavaScript

My Starting Point in Learning JavaScript

I have just started learning JavaScript (JS), and here’s what I have understood so far 👇

What is JavaScript (JS)?

JavaScript (JS) is a scripting and also a programming language.

Scripting means giving small instructions to control something that is already built like a browser or system.

For example: HTML and CSS make a website, but if we want to add interactions (like when we click a button and its color changes to red), we use JavaScript. So, with JS we give instructions to the browser to make it do something.

JavaScript was created by Brendan Eich, who worked at Netscape, a web browser company. He first made a JS engine called Mocha, which later became JavaScript.

As a programming language, JavaScript can also be used to make full mobile apps, websites, servers, and backend systems for example, with tools like React Native or Node.js.

Why is JavaScript important?

Because it helps us interact with browsers. Without JS, websites are only static pages. With JS, we can make websites interactive and dynamic.

What can JavaScript do?

  • Make animations
  • Handle form validation
  • Create and control pop-ups
  • Change elements when you click buttons
  • And much more...

Ways to use JavaScript

We can use JavaScript in two ways:

  1. Write JS code inside the <script> tag directly in an HTML file.
  2. Attach an external .js file using the <script> tag.

var, let, and const

var and let are used to make variables, and const is used to make constants.

Variables are containers that hold data. The data can be numbers, text, arrays, or even functions. We use variables to store data and use it later.

Constants are used when the value never changes for example, the value of π (pi) is always 3.14.

var

  • Came in ES5
  • Adds itself to the window object
  • Function scoped
  • Can be redeclared and reassigned
  • No TDZ (Temporal Dead Zone)

let and const

  • Came in ES6
  • Do not add themselves to the window object
  • let cannot be redeclared but can be reassigned
  • const cannot be redeclared or reassigned
  • Have TDZ

What is a String?

Anything written inside ' ', " ", or is called a string.

Common string methods: slice(), splice(), replace(), includes(), replaceAll()

Template Literals

Before template literals, we used the plus (+) operator to join text, like this:

let a = 10;
let b = 20;
console.log(a + b + " is " + "20" + " and " + a - b + " is " + 10);        

This was confusing and sometimes caused errors.

With template literals, it becomes much easier:

console.log(`${a}+${b} is 30 and ${a}-${b} is 10`);        

Template literals make code clean, simple, and easy to read.

This is how I started learning JavaScript step by step, from the basics!

To view or add a comment, sign in

More articles by Muhammad Waleed

Explore content categories