🗂️Javascript Basics

📒Values and Variables:-

🔹Primitive Types:-

  • Numbers

  • String

  • Boolean

  • Null

  • Undefined


🤔Where to Run Javascript Code

Running Code in Console is the Easiest place to start. Early on, we'll run our code using the Chrome developer tools console. Then we'll learn how to write external scripts.

To open the console in your machine,

  1. Open your Web browser (Chrome recommended).

  2. Open a new tab and right-click on the screen, you will have a pop-up modal and select Inspect.

  3. On the sidebar, you will a section where you can access the Elements of your web page and just to it's next there is the console.

  4. Click on Console and write your code there.

⚠️Alert: - The Code written here will not be saved in your local machine, on refreshing the page the code will disappear.


  1. Numbers:-

50 // Integer
7
3.874
0.99 // Float 
-45  // Negative number of Integer type
-777.2444 // Negative number of type Float
  • JS has One number type

  • Positive Numbers

  • Negative Numbers

  • Whole Numbers (Integers)

  • Decimal Numbers

🔹Math Operations:-

//Addition
50 + 5  //55

//Subtraction
40 - 10  //30

//Multiplication
1111 * 7  //7777

//Division
400 / 25  //16

//Modulo
27 % 2  // 1

📝Note:- ' // ' Creates a comment ( the line is ignored ).


✨NaN:-

NaN: Not a Number is a numeric value that represents something that is... not a number.

0/0 // NaN

1 + NaN // NaN

❓Questions:-

What does this evaluate?

// Try yourself
4 + 3 * 4 / 2 

(13 % 5) ** 2

200 + 0/0

🔹Variables:-

👉Variables are like Labels for values.

  • We can store a value and give it a name so that we can:

  • Refer it back

  • Use a value to do stuff.

  • Or change it later on

🔹Syntax:-

let someName = value;

//Example:-
let year = 1986;
// It say make a variable called 'year' and give it a value of 1986.

📝 Note:-

1️⃣ The let keyword was introduced in ES6 (2015).

2️⃣ Variables defined with let can not be redeclared.

3️⃣ Variables defined with let must be declared before use.

4️⃣ Variables are defined with let have block scope.

🔹Recall Values:-

let computers = 4

let keyboards = 3

computers + keyboards // 7

// Changing Values:-
computers - 1; // 3
//It does not change the original value.
computers; // 4

//To actually change computers:
computers = computers - 1;
computers; // 3

Const:-

  1. The const keyword was introduced in ES6 (2015).

  2. Variables defined with const cannot be Redeclared.

  3. Variables defined with const cannot be Reassigned.

  4. Variables defined with const have Block Scope.

const computers = 4;
computers = 20;   //ERROR!!

const keyboard = 7;
keyboard = keyboard + 1; //ERROR!!

📝 Note:- const works like let, except you CANNOT change the value.


🔹Var:-

👉Before let and const, var was the only way of declaring variables. These day's there isn't really a reason to use it.


  1. Boolean:-

    It's Basically True or False.

let loggedin = true;

let gameover = false;

⚠️ALERT:-

Variables can change types.

let computers = 5;  // Number
commputers = false; // Boolean
computers = 100; // Back to Number

Thanks for Reading all Along🙏