JavaScript Fundamentals - Part Two Flashcards
What is the importance of “use script” in JavaScript?
It helps us to prevent unnecessary action to happen and also allow us to “throw” exceptions in detail for a more clear and safe code.
What are Functions in JavaScript?
Functions is one of the fundamental building blocks in JavaScript. A function is similar to a procedure–a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is obvious relationship between the input and the output.
What is the difference between Function Declaration and Function Expression?
Differences, actually. Expressed functions cannot be used before initialization. Expressed functions need to be assigned to be used later. Anonymous functions are useful for anonymous operations, so you can use a function expression instead of a function declaration in that regard as well.
What is the use of Arrow Functions in JavaScript? And its limitations?
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage: Arrow functions don’t have their own bindings to “this”, “arguments”, or “super”, and should not be used as methods. Arrow functions cannot be used as constructors, calling them with new throws a TypeError. They also don’t have access to the new.target keyword. Arrow functions cannot yield within their body and cannot be created as generator functions.
What are Callback Functions?
Functions passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
What is an Array in JavaScript?
An array in JavaScript is a type of global object that is used to store data. Arrays consist of an ordered collection or list containing zero or more data types, and use numbered indices starting from 0 to access specific items.
What are the basic Arrays operation methods?
.push, .unshift, .pop, .shift, Element.indexOf, Element.includes.
What is an Object in JavaScript?
An object is a collection of properties, and a property is an association between a name (or key) and a value. A property’s value can be a function, in which case the property is known as a method. Objects in JavaScript, just as in many other programming languages, can be compared to objects in real life.
What is the difference between Dot and Bracket notation?
Dot notation is useful when you know the property ahead of time. You simply do object.key to read/modify an existing property or to add a new property. Bracket notation is useful when you want to dynamically access a property.
Explain “this” in JavaScript. What is it used for?
In JavaScript, the “this” keyword refers to an object. Which object depends on how “this” is being invoked (used or called): In an object method, “this” refers to the object. Alone, “this” refers to the global object. In a function, “this” refers to the global object. In a function, in strict mode, “this” is undefined. In an event, “this” refers to the element that received the event. Methods like call(), apply(), and bind() can refer “this” to any object.
What is the For Loop in JavaScript?
The for loop is an iterative statement which you use to check for certain conditions and then repeatedly execute a block of code as long as those conditions are met.
Write a For Loop.
for (initialization; condition; updater) {
— code to be executed —
}
What is the difference between break and continue in JavaScript?
The break statement “jumps out” of a loop. The continue statement “jumps over” one iteration in the loop.
Write a backwards For Loop.
for (let i = Elements.length - 1; i >= 0; i–) {
— code to be executed —
}
Write a Nested For Loop.
for (let i = 0; i < Elements.length; i++) {
— code to be executed —
for (let j = 0; j < ElementsB.length; i++ {
— code to be executed —
}
}