Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

switch variable scope js

/* curly braces inside the case */

const i = 1

switch (i) {
  case 0: {
    let x = 2342;
    let s = 1 + x;
    console.log(x+' & '+s+' from inside');
  } break;
  case 1: {
    let x = 2342;
    let s = 'b';
    console.log(x+' & '+s+' from inside'); /* 2342 & b from inside */
  } break;
}

console.log(x+' & '+s+' from outside'); /* Uncaught ReferenceError */
Comment

PREVIOUS NEXT
Code Example
Javascript :: solutions on Multiply - Declaring a Function as a Variable 
Javascript :: Decodes a string of data which has been encoded using base-64 encoding - Nodejs 
Javascript :: javascript if null use other value 
Javascript :: javascript loop arrays 
Javascript :: jquery to animate a flash to the button selected 
Javascript :: fetch an webpage and parse js 
Javascript :: how to auto click webpage in angular 
Javascript :: press enter reaction js 
Javascript :: File to XHR-requests 
Javascript :: setstate before function react 
Javascript :: how to send json data to server in android using volley 
Javascript :: Load Balance 4 instances of api.js node js 
Javascript :: vanilla js game loop 
Javascript :: 4.8. Input with readline-sync¶ 
Javascript :: bjsmasth update 
Javascript :: click eventlistener is not works on radio button using javascript 
Javascript :: moment format escape 
Javascript :: vuex get data in mounted 
Javascript :: midpointrounding.awayfromzero javascript 
Javascript :: javascript reassignment 
Javascript :: how to detect keyboard layout js 
Javascript :: order by ascending descending in angular 6 on click of button 
Javascript :: use chai immutable 
Javascript :: react native return null 
Javascript :: 1493449952 
Javascript :: Comparing traditional functions to arrow functions 
Javascript :: Contentful Migration - Transform Entires 
Javascript :: javascript decode base64 
Javascript :: convert to arrow functions 
Javascript :: type.js 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =