@jgCarroll/

loggingXAndY

JavaScript

A common interview question

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(function() {
  var x = y = 200;
})();
 
console.log('y: ', y);// var Y is a global variable because it is declared without the var keyword
console.log('x: ', x);// var X is defined within the scope of the IIFE, so it is not available outside the function

// ===============================
// essentially, the code above is interpreted like this

(function() {
  y = 200;
  var x = y
})();

// also note that if I added 'use strict' to the top of the file, var y wouldn't log either.
Native Browser JavaScript