Learn Js with me.

Features of JavaScript

  1. Light weight interpreted programming language.

    which means interpreter (an software) reads and executes the code line-by-line. It is also known as just-in-line compiled language.

  2. First-class language.

    means functions in this language are treated like any other variables. Functions can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable.

     const welcome = () => {
     console.log("welcome");
     };
    
     welcome(); //Invoke it using the variable
    

    Here we assigned an Anonymous Function in a variable, then we used that variable to invoke the function by adding parentheses () at the end.

  3. Prototype-based language.

    These languages are currently proposed as a substitute to class-based languages for a higher flexibility in manipulating objects.

  4. Multi-paradigm language.

    It refers to the ability to use different programming styles, such as procedural or object-oriented programming.

  5. Single-threaded language.

    JavaScript is a single threaded language means it has only one call stack it can only execute tasks one by one.

     const myTimeout = setTimeout(myGreeting, 5000);
    
     function myStopFunction() {
       clearTimeout(myTimeout);
     }
    

    Yet been single threaded it uses asynchronous execution when needed (asynchronous refers to execution that doesn't run un sequence). Many methods like setTimeout() (that requires extra time to execute) are asynchronously executed. In this call stack pop that method out and sent it to web API, when web API is done with the execution, it will arrive at the call back queue. The engine checks if the call stack is empty. If it is empty, then we check callback queue which has the instruction setTimeout in it. The callback queue sends it to call back stack and the instruction is executed.

  6. Dynamic Language

    Dynamically-typed languages are those where the interpreter assigns variables a type at runtime based on the variable's value at the time.

Variables

containers that store values.

const accountId= 1828793;
/* const variable can be initialized
 once after than it cannot be change */

let accountE="kjdkbkbabka"
/* let variable can be changed*/

var accountp="hvdjvd"
/*
Prefer not to use var
because of issue in block scope and functional scope
*/

Datatypes.

There generally two types of datatypes Primitive and Non-Primitive Datatype.

Primitive data type are data types which cannot be further divided into simpler data type. There are 7 types of primitive data types.

  1. Number

  2. BigInt

  3. String

  4. Boolean

  5. NULL

  6. Undefined

  7. Symbol

Non primitive data types are user defined data types. Some of the example are String, array, objects, classes.

Data type Conversion.

let score = "123";
console.log(typeof score);
let valueInNumber=Number(score);
console.log(typeof valueInNumber);

/* similarly we can type convert any data type
 String();
 Boolean();
etc
*/

Stack and Heap memory

All the primitive data types are stored in stack, and all the non primitive data types are stored in heap.

In stack we always gets a copy of value but in heap we get a reference

let myYoutubename="aakash";
let anothername= myYoutubename;
// here a copy of value from stack

anothername="anand"
console.log(myYoutubename);
console.log(anothername);
//Aakash
//anand

let userOne={
email:"aakash@gmail.com";
}

let userTwo=userOne;
//here a reference  of value is passed from heap
userTwo.email="Anand@gmail.com"

console.log(userOne.email)
console.log(userTwo.email)
//Anand@gmail.com
//Anand@gmail.com