Ad. Javascript.info part 4 Flashcards
Advanced working with functions Global object Function object, NFE The "new Function" syntax Scheduling: setTimeout and setInterval
In a browser it is named _______for Node.js it is ______, for other environments it may have another name.
“window”,
“global”
alert(“Hello”);
// the same as \_\_\_\_\_\_\_\_\_alert("Hello");
window.
Open Google using alert
window.open(‘http://google.com’);
shows the browser window height with alert
alert(window.innerHeight); //
Top-level_______ variables and _________automatically become properties of window.
var
Function decelerations
var x = 5;
alert(window.x); //
window.x = 0;
alert(x); //
5 (var x becomes a property of window)
0, variable modified
let x = 5;
alert(window.x);
undefined
the value of “this” in the global scope is ______.
window
As of now, the multi-purpose window is considered a design mistake in the language to avoid this Javascript has a built in ______
modules.
fix script below so x becomes “undefined”.
var x = 5;
alert(window.x);
let x = 5;
alert(window.x); // undefined
let x = 5;
alert(x); //
5
alert(this); //
undefined
Using global variables is generally discouraged.
TRUE / FALSE
TRUE
There should be as few global variables as possible, but if we need to make something globally visible, we may want to put it into________ or _______
window
global
As we already know, functions in JavaScript are_____.
Every value in JavaScript has a type. What type is a function?
In JavaScript, functions are _________
values
objects
function sayHi() { alert("Hi"); }
alert(sayHi.name); //
sayHi
function sayHi() { alert("Hi"); }
alert(__________); // sayHi
sayHi.name
WRITE AS A FUNCTION DECLEARATION
let sayHi = function() { alert("Hi"); }
function sayHi() { alert("Hi"); }
function f2(a, b) {}
alert(f2.length); //
2
function many(a, b, ...more) {} alert(many.length); //
2
A property is a variable
TRUE / FALSE
FALSE
A property is not a variable
function sayHi() { alert("Hi"); sayHi.counter++; } sayHi.counter = 0;
sayHi(); // Hi
sayHi(); // Hi
console.log(sayHi.counter);
2