<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Md Alfaz Hossain</title>
    <description>The latest articles on DEV Community by Md Alfaz Hossain (@alfaz08).</description>
    <link>https://dev.to/alfaz08</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1194179%2F3bd7908f-46ae-4054-889c-469969cb4414.jpeg</url>
      <title>DEV Community: Md Alfaz Hossain</title>
      <link>https://dev.to/alfaz08</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alfaz08"/>
    <language>en</language>
    <item>
      <title>JavaScript Objects Unleashed: A Journey into Properties, Methods, and Prototypes</title>
      <dc:creator>Md Alfaz Hossain</dc:creator>
      <pubDate>Mon, 08 Jan 2024 18:24:00 +0000</pubDate>
      <link>https://dev.to/alfaz08/javascript-objects-unleashed-a-journey-into-properties-methods-and-prototypes-14j1</link>
      <guid>https://dev.to/alfaz08/javascript-objects-unleashed-a-journey-into-properties-methods-and-prototypes-14j1</guid>
      <description>&lt;p&gt;Hello, enthusiastic developers today I will take a deep dive into the JavaScript object. Let's start.....&lt;/p&gt;

&lt;p&gt;First of all, in JavaScript Object is called king. Anyone who can understand object property can understand JavaScript easily.&lt;br&gt;
An object in JavaScript is a collection of key-value sometimes called name-values. Each key-value pair is called a property. A property can be a function, an array, an object itself, or any primitive data type such as an integer, or string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const player = {
 firstName: "David",
 lastName: "Cameron",
 age:30,
 fullName: function(){
    return this.firstName + "  "+ this.lastName
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Way of access of object property:&lt;/strong&gt;&lt;br&gt;
There are two ways of accessing object property&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Dot notation &lt;br&gt;
2.Square bracket notation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dot Natation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;player.firstName // output is David
player.fullName() //output is David Cameron
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Square bracket Notation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;player["firstName"] // output is David
player["age"] //output is 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Notes: *&lt;/em&gt; Another way of accessing objects is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x= "age"
player[x]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Delete object property:&lt;/strong&gt;&lt;br&gt;
To delete a property from an object we can use the delete keyword.&lt;/p&gt;

&lt;p&gt;delete player.firstName//return true and delete firstName property&lt;/p&gt;

&lt;p&gt;Let's see what happens if we try yo call the fullName method which uses both firstName and lastName property of the player object but we have deleted the firstName&lt;/p&gt;

&lt;p&gt;console.log(player.fullName()) //output is undefined Cameron&lt;/p&gt;

&lt;p&gt;output return undefined in firstName because we trying to access a property of the player object that does not exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object Method:&lt;/strong&gt;&lt;br&gt;
A function that is used as an object property is the call method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const player = {
 firstName: "David",
 lastName: "Cameron",
 age:30,
 fullName: function(){
    return this.firstName + "  "+ this.lastName
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here fullName() is an object method.&lt;/p&gt;

&lt;p&gt;To check if an object has a property using the hasOwnProperty method. When the property is available in the object it will return true otherwise return false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(player.hasOwnProperty('firstName')) //output is true
console.log(player.hasOwnProperty('middleName')) //output is false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To loop through the properties of an object use normally for...in loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const player = {
 firstName: "David",
 lastName: "Cameron",
 age:30,
 fullName: function(){
    return this.firstName + "  "+ this.lastName
   }
}


for (let x in player) {
  console.log(player[x])
} 
//output is
David
Cameron
30
[Function: fullName]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A constructor function is a function that is used to create new objects with the same properties and methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function player(name,age){
 this.name = name,
 this.age =age
}

let x = new player ('Messi',35)
let y = new player ('Ronaldo',37)

function player(name,age){
 this.name = name,
this.age =age
}

let x = new player ('Messi',35)
let y = new player ('Ronaldo',37)

console.log(x)
console.log(y)

//output is 
player { name: 'Messi', age: 35 }
player { name: 'Ronaldo', age: 37}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Beyond Syntax: Exploring the Depths of JavaScript Functions</title>
      <dc:creator>Md Alfaz Hossain</dc:creator>
      <pubDate>Fri, 05 Jan 2024 15:17:14 +0000</pubDate>
      <link>https://dev.to/alfaz08/demystifying-javascript-functions-a-deep-dive-into-power-and-flexibility-4ick</link>
      <guid>https://dev.to/alfaz08/demystifying-javascript-functions-a-deep-dive-into-power-and-flexibility-4ick</guid>
      <description>&lt;p&gt;Hello, developers today I will dive into the JavaScript functions. Let's start.....&lt;/p&gt;

&lt;p&gt;In JavaScript function is one kind of non-primitive data type. The function is also one kind of object in JavaScript because in JavaScript all non-primitive data types are one kind of object.&lt;br&gt;
A JavaScript function is a block of code designed to perform a particular task. When we use the same logic randomly in our code then we often use function for it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;br&gt;
In JavaScript, we can define a function using the keyword function. A function has the function keyword, followed by aq name and a parenthesis.&lt;br&gt;
The code to be excited by the function is placed inside curly braces {}. A JavaScript function is executed when something invokes it or calls it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(num1,num2){
  let num3 = num1+num2;
  console.log(num3) //output is 13
}
add(8,5)//function call 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function return&lt;/strong&gt;&lt;br&gt;
When JavaScript reaches a return statement the function will stop executing. When a function is invoked or called it will execute after finding the return it will return the value to the caller.&lt;br&gt;
When a function does not return anything it will return undefined implicitly and come out from the function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myCall(){
console.log("hello Bangladesh")//output is hello Bangladesh
}
let x= myCall();
console.log(x) //output is undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function declaration and function expression&lt;/strong&gt;&lt;br&gt;
A function declarations means the normal function declaration like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sleep(){
console.log("I am sleeping")
}
sleep()// output is I am sleeping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But function expression is a bit different. When a function is stored in a variable and called with a variable name is called a function expression&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = function(){
console.log("Hello Bangladesh")
}
a() // output is Hello Bangladesh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function is also called an anonymous function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function hoisting:&lt;/strong&gt;&lt;br&gt;
Hoisting is a JavaScript behavior of moving declaration on the top of the current scope. When a function is called before it is declared using the JavaScript hoisting method hosited the function at the top of the function call as a result it does not give any error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add(8,5)//function call 
function add(num1,num2){
  let num3 = num1+num2;
  console.log(num3) //output is 13
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But remember function defined using an expression are not hoisted and give an error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add(8,5)//function call 
const add = function(num1,num2){
  let num3 = num1+num2;
  console.log(num3) //give an error
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Self-invoke functions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a function calls itself then it is called self invoke the function &lt;br&gt;
(function(){&lt;br&gt;
console.log("Hello Bangladesh");&lt;br&gt;
})();&lt;/p&gt;

&lt;p&gt;Function Parameters:&lt;br&gt;
When parameters are more than arguments we passed then extra parameters will set value undefined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(num1,num2){
  num3 =num1* num2 // here num1 is 8 ,num2 is undefined
  console.log(num3) //output is NaN
}
add(8,5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>web</category>
      <category>javascript</category>
      <category>programming</category>
      <category>development</category>
    </item>
    <item>
      <title>Type Mastery: Understanding and Leveraging JavaScript's Data Types</title>
      <dc:creator>Md Alfaz Hossain</dc:creator>
      <pubDate>Wed, 03 Jan 2024 04:24:14 +0000</pubDate>
      <link>https://dev.to/alfaz08/type-mastery-understanding-and-leveraging-javascripts-data-types-4bgj</link>
      <guid>https://dev.to/alfaz08/type-mastery-understanding-and-leveraging-javascripts-data-types-4bgj</guid>
      <description>&lt;p&gt;Hello developers today I will describe in depth of data types in JavaScript. Let's start.....&lt;/p&gt;

&lt;p&gt;Every Variable has a data type. Data types specify which kind of data has been stored in a variable. In the border concept, JavaScript has two kinds of data types.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Primitive Data&lt;br&gt;
2.Non-primitive Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now these data types are subdivided into several data types.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zWE0A4lM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p81izr4ug6c7v0gox528.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zWE0A4lM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p81izr4ug6c7v0gox528.jpg" alt="Image description" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primitive Data Types:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Primitive data types are those data types which value once assigned can not changed. There are several primitive data types...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Number&lt;br&gt;
2.String&lt;br&gt;
3.Boolean&lt;br&gt;
4.Undefined&lt;br&gt;
5.Null&lt;br&gt;
6.BigInt&lt;br&gt;
7.Symbol&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Number&lt;/strong&gt;&lt;br&gt;
The number is a basic data type in JavaScript that can hold decimals as well as values without decimals.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x=20;
let x=25.52;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. String&lt;/strong&gt;&lt;br&gt;
String data types represent textual data that are enclosed in single or double quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let programmingLanguage = "Python"
let name="mr.x"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Boolean&lt;/strong&gt;&lt;br&gt;
Boolean data types represent logical values. It can store two values either true or false. Boolean is often used in conditional statements and comparisons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let isRaining =true;
or
let isRaining=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Null&lt;/strong&gt;&lt;br&gt;
JavaScript null means nothing. The types of null is an object. The null data type is the intentional absence of an object value.So if we want a variable to be empty but not undefined set its value to null without a quotation mark.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name= null
console.log(name)// output is null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Undefined&lt;/strong&gt;&lt;br&gt;
A variable that was declared without value has the value or type undefined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name ;
cosnole.log(name) //undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. BigInt&lt;/strong&gt;&lt;br&gt;
BigInt is a new JavaScript data types which is used to store integer values that are too big.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = BigInt("123455777854565468987686546534658787")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Symbol&lt;/strong&gt;&lt;br&gt;
Symbol data types have been used to have a unique result every time they are constructed. You can think of symbols as a special kind of token that can guarantee uniqueness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-primitive or Reference Data:&lt;/strong&gt;&lt;br&gt;
Non-primitive data types is also known as reference data types because it is not directly store the data value rather than store reference to objects in memory. There are three types of non-primitive data types...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Array&lt;br&gt;
2.Object&lt;br&gt;
3.Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Array&lt;/strong&gt;&lt;br&gt;
JavaScript array is written with square brackets. Array items are separated by a comma. Array data types may contain elements of any data type including number, string, object and even another array. Array indexes are zero-based which means the first item is [0].&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let programmingLanguage = ["c","c++","python"]
let oddNumbers =  [201,203,205]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Object&lt;/strong&gt;&lt;br&gt;
The object data type is a versatile and powerful data type in javascript.It allows to store collections of key-value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
name: "John Doe",
Age:25,
Profession: "Web Developer"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Function&lt;/strong&gt;&lt;br&gt;
The function is also considered a data type in JavaScript.The function is reuseable code that can be called, passed as a argument and returned as values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function developer(name)
{
console.log("hello"+name);
}
developer("John Doe") //output is "hello John Doe"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Data Types Checking&lt;/strong&gt;&lt;br&gt;
To check the type of any variable just use &lt;strong&gt;typeof&lt;/strong&gt; operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x=16;
console.log(typeof x) //output is number
let name="John Doe";
console.log(typeof name) //output is string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Data Types Conversion&lt;/strong&gt;&lt;br&gt;
JavaScript allows both implicit and explicit data type conversion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implicit Conversion:&lt;/strong&gt;&lt;br&gt;
Implicit conversion means JavaScript automatically converts the type of data without instruction from the developer. One example is When adding a number and a string JavaScript will treat them as a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x=16+"python"
console.log(x)//output is 16python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explicit Conversion:&lt;/strong&gt;&lt;br&gt;
Explicit Conversion means the developer instructs to convert the value of one data type into another data type using a built-in function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numberString = "123"
let number = Number(numberString) //Explicitly convert string to number
cosole.log(number) //output is 123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>development</category>
    </item>
    <item>
      <title>A Comprehensive overview on let,const,var</title>
      <dc:creator>Md Alfaz Hossain</dc:creator>
      <pubDate>Mon, 01 Jan 2024 18:28:32 +0000</pubDate>
      <link>https://dev.to/alfaz08/a-comprehensive-overview-on-letconstvar-4075</link>
      <guid>https://dev.to/alfaz08/a-comprehensive-overview-on-letconstvar-4075</guid>
      <description>&lt;p&gt;Hello developers today I will describe the JavaScript variables let,var, const on an easy and comprehensive way. Let's start...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of Content&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;var&lt;/li&gt;
&lt;li&gt;let&lt;/li&gt;
&lt;li&gt;const&lt;/li&gt;
&lt;li&gt;summary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JgW7v7n_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuueglg7pnyitjz3hj4a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JgW7v7n_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuueglg7pnyitjz3hj4a.jpg" alt="Source: @mpjme (https://twitter.com/mpjme)" width="720" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In javascript there are 3 types of varibales.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;var&lt;/li&gt;
&lt;li&gt;let &lt;/li&gt;
&lt;li&gt;const&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The var keyword was used in all JavaScript code from 1995 to 2015.&lt;br&gt;
The let and const keyeword were added to JavaScript in 2015.&lt;/p&gt;

&lt;p&gt;A variable declared without a value will have the value undefined.&lt;br&gt;
&lt;code&gt;let fruit;&lt;br&gt;
console.log(fruit)//undefined&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Var&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Var is a global scope variable in JavaScript.Before ES6 var was vastly used in JavaScript.var is a type of variable that has been used both locally and globally. A variable declared with var always has a global scope and cannot have a block scope. When a var variable is declared it can be changed from anywhere. That creates a problem.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var a= 10;//the value of a is 10&lt;br&gt;
var a=12;//the value of a is 12&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Scope&lt;/strong&gt; means a variable that is declared anywhere inside or outside the function and can be accessed from anywhere inside or outside those functions.&lt;br&gt;
&lt;strong&gt;Block Scope&lt;/strong&gt; means a variable that is declared inside a function can only access inside the function and cannot access from outside of the function. In an easy word, a block refers to anything within the curly braces {}.&lt;br&gt;
Before ES6 JavaScript did not have a block scope function JavaScript has global and function scope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let&lt;/strong&gt;&lt;br&gt;
Let is a block scope variable and must be declared before use. As a block scope variable let cannot be accessed from outside of the block scope.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function call(){&lt;br&gt;
let x=12;&lt;br&gt;
console.log(x)//the value of x is 12&lt;br&gt;
}&lt;br&gt;
call();&lt;br&gt;
console.log(x)//give an error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;let is such kind of variable which is not redeclared in the same scope but redeclared in a different scope.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let x =10;&lt;br&gt;
let x=2//can not redeclared give an error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now this situation&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let x =10//the value of x is 10&lt;br&gt;
{&lt;br&gt;
let x=5//the value of x is 5&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;let is a variable which value can be reassigned in same scope&lt;br&gt;
&lt;code&gt;let x =10&lt;br&gt;
x=12;&lt;br&gt;
console.log(x)//output is 12&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Const&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Const is a block scope varibale.In modern JavaScript, most of the time variable declaration const has been used.A variable defined with const can not be redeclared and reassigned.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const x =10;&lt;br&gt;
x=x+10;//this will give an error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Const variables must be assigned a value when they are declared.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const x;&lt;br&gt;
x=10;//this will give an error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Always declare a variable with const when you know that the value should not be changed.Use const when you declare:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Array&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;li&gt;Function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The keyword const is a little tricky because does not define the constant value rather it is defined constant reference to a value.&lt;br&gt;
For this reason, when we use const cannot&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reassign a constant value&lt;/li&gt;
&lt;li&gt;Reassign a constant array&lt;/li&gt;
&lt;li&gt;Reassign a constant object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But we can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change the element of a constant array&lt;/li&gt;
&lt;li&gt;Change the properties of a constant object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;const fruit =["mango","Orange","Apple"]&lt;br&gt;
const[0]="Watermelon"//you can change an element&lt;br&gt;
fruits.push("strawberry"//you can add an element&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But can not assign&lt;br&gt;
&lt;code&gt;const fruit =["mango","Orange","Apple"]&lt;br&gt;
fruit =["mango","Orange","Apple","Watermelon"]//give an error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Variable hoisting&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A variable defined with var is hoisted to the top and can be initialized at any time which means one can use a variable before it is declared;&lt;br&gt;
&lt;code&gt;console.log(fruit)//output is Apple&lt;br&gt;
var fruit="Apple";&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
A variable defined with let and const is also hoisted to the top but not initiated as a result when using a const or let variable before it was declared to give a ReferenceError.&lt;br&gt;
One point noted for const it will already give syntaxError because in const must declare with value without it will give syntaxError before referenceError.&lt;br&gt;
&lt;code&gt;console.log(fruit)//give an error&lt;br&gt;
const fruit="Apple";&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;When to use var, let or const&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always use const if the value should not changed.&lt;/li&gt;
&lt;li&gt;Always use const if the type should not changed.&lt;/li&gt;
&lt;li&gt;Use let when can not use const.&lt;/li&gt;
&lt;li&gt;Use let when the variable needs to be reassigned.&lt;/li&gt;
&lt;li&gt;Use var when needs to reassign,redeclare and hoisting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Variable Lifetime&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;**Global variables **live until the page is discarded, like when you navigate to another page or close the window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Local variables&lt;/strong&gt; have short lives. They are created when the function is invoked and deleted when the function is finished.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
In the end in one word we can say that-&lt;br&gt;
&lt;strong&gt;var:&lt;/strong&gt;global-scoped and can be redeclared, or reassigned.&lt;br&gt;
&lt;strong&gt;let:&lt;/strong&gt;block-scoped and can not be redeclared but can be reassigned.&lt;br&gt;
&lt;strong&gt;const:&lt;/strong&gt;block-scoped and can not be redeclared, or reassigned.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
