From b82fe26ac336685652dc595a626423d65f0eadd5 Mon Sep 17 00:00:00 2001 From: Swati Singh <27953384+swatisingh-in@users.noreply.github.com> Date: Sat, 5 Feb 2022 19:43:59 +0100 Subject: [PATCH] add example for block scope --- .../01_javascript_refresher.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/01_Day_JavaScript_Refresher/01_javascript_refresher.md b/01_Day_JavaScript_Refresher/01_javascript_refresher.md index 7460b26..636b4c6 100644 --- a/01_Day_JavaScript_Refresher/01_javascript_refresher.md +++ b/01_Day_JavaScript_Refresher/01_javascript_refresher.md @@ -311,6 +311,18 @@ const PI = 3.14 // Not allowed to reassign PI to a new value // PI = 3. ``` +``` +const x = 10; + +if (x > 10) { + const y = 15; +} else { + const y = 20; +} + +console.log(y); // y is not accessible because const and let are block scoped. +``` + ### 2. Data types If you do not feel comfortable with data types check the following [link](https://github.com/Asabeneh/30-Days-Of-JavaScript/blob/master/02_Day_Data_types/02_day_data_types.md)