let's talk about let keywords in javascript

let's talk about let keywords in javascript

do you know that var is faster than let while running inside a loop?

Β·

2 min read

Hi there, Know that I'm filled with joy having you today! Your presence brings warmth to my heartπŸ’“

so let's dive in πŸ˜‰...

What are Keywords?

what are keywords to begin with? Keywords are reserved words that are part of the syntax in the programming language.

for example

let a = 'hello';

Here, let is a keyword that denotes that a is a variable.

How many keywords are used in JavaScript?

There are three keywords in javascript which are

  1. var

  2. let

  3. const

What's the let keyword then?

The let keyword is used to declare variables in JavaScript. The var keyword can also be used to declare variables, but the key difference between them lies in their scopes.

Note: The let keyword was introduced in ES6 (2015).

var is function scoped while let is block scoped.

function scoped variables: A function-scoped variable means that the variable defined within a function will not accessible from outside the function.

block-scoped variables: A block-scoped variable means that the variable defined within a block will not be accessible from outside the block.

Note: let can be updated but not re-declared.

let name  = "Abraham";
name = "Elebute";

Note: In terms of performance comparison, var is faster, and let is slower inside the loops while running or executing the code.

Hope you enjoyed your reading, Stay tuned! Peace out ✌😎.

Β