Difference between var, let and const in javascript

In JavaScript, `var`, `let`, and `const` are all used to declare variables, but they have different scoping rules and behaviors:
`var`: Variables declared with `var` are function-scoped, which means they are only accessible within the function where they are declared or in the global scope if declared outside of a function. However, `var` declarations are hoisted to the top of their scope, which means they can be accessed before they are declared. Also, `var` variables can be re-declared and updated within their scope.
                                            
                                        
                        // Example with var
function exampleVar() {
  var x = 1;
  if (true) {
    var x = 2; // This re-declares the variable
    console.log(x); // Output: 2
  }
  console.log(x); // Output: 2
}
exampleVar();                    
                
`let`: Variables declared with `let` are block-scoped, which means they are only accessible within the block where they are declared (e.g., within a loop or if statement). Unlike `var`, `let` variables are not hoisted, which means they cannot be accessed before they are declared. Also, `let` variables can be updated within their scope, but not re-declared.
                                            
                                        
                        // Example with let
function exampleLet() {
  let x = 1;
  if (true) {
    let x = 2; // This creates a new variable within the block
    console.log(x); // Output: 2
  }
  console.log(x); // Output: 1
}
exampleLet();                    
                
`const`: Variables declared with `const` are also block-scoped and cannot be re-declared or updated within their scope. However, `const` variables can still be mutable, which means you can modify the properties of objects or arrays assigned to a `const` variable. `const` variables are commonly used to declare constants or values that should not be changed.
                                            
                                        
                        // Example with const
function exampleConst() {
  const x = { value: 1 };
  x.value = 2; // This modifies the object assigned to x
  console.log(x.value); // Output: 2
}
exampleConst();                    
                
Here are some examples to illustrate the differences:
I hope this helps clarify the differences between `var`, `let`, and `const` in JavaScript!