3.7 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.7 KiB
		
	
	
	
	
	
	
	
id, title, challengeType, videoUrl, localeTitle
| id | title | challengeType | videoUrl | localeTitle | 
|---|---|---|---|---|
| 56533eb9ac21ba0edf2244be | Global Scope and Functions | 1 | Глобальная область и функции | 
Description
var , автоматически создаются в global области. Это может привести к непредвиденным последствиям в другом месте вашего кода или при повторном запуске функции. Вы всегда должны объявлять переменные с помощью var . Instructions
var , объявляйте global переменную myGlobal вне любой функции. Инициализируйте его со значением 10 . Внутри функции fun1 присвойте 5 oopsGlobal без использования ключевого слова var . Tests
tests:
  - text: <code>myGlobal</code> следует определить
    testString: 'assert(typeof myGlobal != "undefined", "<code>myGlobal</code> should be defined");'
  - text: <code>myGlobal</code> должен иметь значение <code>10</code>
    testString: 'assert(myGlobal === 10, "<code>myGlobal</code> should have a value of <code>10</code>");'
  - text: <code>myGlobal</code> следует объявить с помощью ключевого слова <code>var</code>
    testString: 'assert(/var\s+myGlobal/.test(code), "<code>myGlobal</code> should be declared using the <code>var</code> keyword");'
  - text: <code>oopsGlobal</code> должен быть глобальной переменной и иметь значение <code>5</code>
    testString: 'assert(typeof oopsGlobal != "undefined" && oopsGlobal === 5, "<code>oopsGlobal</code> should be a global variable and have a value of <code>5</code>");'
Challenge Seed
// Declare your variable here
function fun1() {
  // Assign 5 to oopsGlobal Here
}
// Only change code above this line
function fun2() {
  var output = "";
  if (typeof myGlobal != "undefined") {
    output += "myGlobal: " + myGlobal;
  }
  if (typeof oopsGlobal != "undefined") {
    output += " oopsGlobal: " + oopsGlobal;
  }
  console.log(output);
}
Before Test
var logOutput = "";
var originalConsole = console
function capture() {
    var nativeLog = console.log;
    console.log = function (message) {
        logOutput = message;
        if(nativeLog.apply) {
          nativeLog.apply(originalConsole, arguments);
        } else {
          var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
          nativeLog(nativeMsg);
        }
    };
}
function uncapture() {
  console.log = originalConsole.log;
}
var oopsGlobal;
capture();
After Test
console.info('after the test');
Solution
// solution required