Coder Social home page Coder Social logo

zero_day's Introduction

Hello👋🏼

I'm Bilal, A seasoned developer. I have few projects and I'm currently undergoing a SE course.

I'll be writing a few articles on some Js concepts which would be helpful to beginners

Article1: The difference between let and const in Javascript

Let and const image ("Let and const")

In Javascript, let and const are both used to declare variables, but they have some key differences in terms of how they can be assigned and their mutability.

  1. let:
  • Variables declared with let are mutable, which means their values can be changed after they are assigned.
  • let allows you to reassign a new value to the variable later in your code.
  • Variables declared with let have block scope, which means they are only accessible within the block they are defined.
  • You can declare a variable with let without necessarily assigning it a value right away. Example:
let age = 25;
age = 26; // Value can be changed
  1. const:
  • Variables declared with const are also block-scoped like let.
  • However, const variables are immutable, which means their value cannot be canged after they are assigned.
  • You must assign a value to a const variable when it is declared, and you cannot reassign it later. Example:
const pi = 3.14159;
//pi = 3.14; // This would result in an error
  1. When to Use Each:
  • Use let when you need to reassign the variable's value or its value will change overtime.
  • Use const when you want to declare a variable that won't change its value and to enforce immutability for variables that should remain constant.

Choosing between let and const depends on the use case and whether you expect the value of the variable to change. It's a good peactice to use const whenever possible, as it makes your code more predictable and helps prevent unintentional changes to variables that should remain constant. use let when you know the variable's value will change or when you need the flexibility to reassign it.

zero_day's People

Contributors

muilibilal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.