3.1 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.1 KiB
		
	
	
	
	
	
	
	
id, title, challengeType, videoUrl, localeTitle
| id | title | challengeType | videoUrl | localeTitle | 
|---|---|---|---|---|
| 56533eb9ac21ba0edf2244be | Global Scope and Functions | 1 | Ámbito global y funciones | 
Description
var se crean automáticamente en el ámbito global . Esto puede crear consecuencias no deseadas en otra parte de su código o al ejecutar una función nuevamente. Siempre debes declarar tus variables con var . Instructions
var , declare una variable global myGlobal fuera de cualquier función. Inicialízalo con un valor de 10 . Dentro de la función fun1 , asigne 5 a oopsGlobal sin usar la palabra clave var . Tests
tests:
  - text: <code>myGlobal</code> debe ser definido
    testString: 'assert(typeof myGlobal != "undefined", "<code>myGlobal</code> should be defined");'
  - text: <code>myGlobal</code> debe tener un valor de <code>10</code>
    testString: 'assert(myGlobal === 10, "<code>myGlobal</code> should have a value of <code>10</code>");'
  - text: <code>myGlobal</code> debe declararse usando la palabra clave <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> debe ser una variable global y tener un valor de <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