When an event is fired from an element, the event will be bubbled up to its
parent nodes. However, the original element where the event occurs, called
'target', stays the same in the event object. Using the target
property, we
can always keep tracking which element actually causes an event captured by
its parent, and it can help use reduce the number of event handlers as we
sometimes don't need to add event listeners for every element.
Not answered yet
Not answered yet
Not answered yet
Not answered yet
(function foo() { })(); // or
(function foo() { }());
Not answered yet
Not answered yet
Not answered yet
Not answered yet
- Host objects: what an environment(browser, Node.js, etc) provides
- Native objects: what JavaScript provides
Not answered yet
Not answered yet
Not answered yet
When someone gives me one million dollar for doing it.
- Feature detection: directly check if a feature is implemented
if (Promise) {
let a = Promise.resolve('hello');
}
- Feature inference: infer if a feature is implemented by checking other properties
if (MozSmsMessage) {
// guess it must be Firefox...
}
- UA string: UA stands for UserAgent, which a browser natively exposes to scripts and HTTP header
console.log(navigator.userAgent); // "Mozilla/5.0 (Macintosh; ..."
Not answered yet
A JSONP response contains a callback function usually written in JavaScript, and when the response is flushed, the callback will be launched. It's more like script tag injection, rather than AJAX.
Yes.
Handlebars, Mustache, etc.
Not answered yet
It's when an event is bubbled into container elements, in the higher level of a DOM tree.
- Attribute: specified in HTML, always in the form of string
- Property: specified in DOM object, can have any type of JavaScript
Not answered yet
- document ready: when a HTML document is loaded and rendered
- document load: when a HTML document and assets in the document are all loaded and rendered
Not answered yet
Same-origin means having same host, port and protocol(HTTP or HTTPS). If a script in the different origin should be accessed, we can consider using CORS.
duplicate([1,2,3,4,5]); // [1,2,3,4,5,1,2,3,4,5]
let duplicate = (arr) => arr.concat(arr);
Not answered yet
Advantages
- Cannot assign a value to an undefined global variable
- Fire TypeError for not-allowed assignments
this
in a normal function refers toundefined
, instead ofglobal
In short, it secures JavaScript.
Disadvantage
- When using global strict mode and concatenating the script with other scripts not using strict mode, the other scripts can be broken.
Create a for loop that iterates up to 100
while outputting "fizz" at multiples of 3
, "buzz" at multiples of 5
and "fizzbuzz" at multiples of 3
and 5
Not answered yet
Not answered yet
Why would you use something like the load
event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?
Not answered yet
Not answered yet
Not answered yet
Not answered yet
What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript?
Not answered yet
Not answered yet
Not answered yet
Not answered yet
Not answered yet
Not answered yet