Created
February 2, 2018 09:45
-
-
Save aliaspooryorik/01db81e0628ed9aa8137aad5c08c8923 to your computer and use it in GitHub Desktop.
block scope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyClass { | |
public static void main(String args[]) { | |
int x=10; | |
for (int i=0; i != 100; i++) { | |
int a = x+i; | |
} | |
System.out.println("X is = " + x); | |
System.out.println("A is = " + a); | |
} | |
} | |
https://www.jdoodle.com/online-java-compiler | |
/MyClass.java:10: error: cannot find symbol | |
System.out.println("A is = " + a); | |
^ | |
symbol: variable a | |
location: class MyClass | |
1 error | |
// CFML | |
<cfscript> | |
function main() { | |
var x=10; | |
for (var i=0; i != 100; i++) { | |
var a = x+i; | |
} | |
writeOutput("X is = " & x); | |
writeOutput("A is = " & a); | |
} | |
main(); | |
</cfscript> | |
X is = 10A is = 109 | |
// old skool JS | |
(function () { | |
var x=10; | |
for (var i=0; i != 100; i++) { | |
var a = x+i; | |
} | |
console.log("X is = " + x); | |
console.log("A is = " + a); | |
})(); | |
// ES6 JS | |
(() => { | |
const x=10; | |
for (let i=0; i != 100; i++) { | |
let a = x+i; | |
} | |
console.log("X is = " + x); | |
console.log("A is = " + a); | |
})(); | |
// a is undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment