Vocab/Methods definitions Flashcards

1
Q

What are the primitive data types that cannot be mutated? So in other words, what are the primitive types?

A

Primitive types are String, Number, Boolean, null, undefined and symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What data types CAN be mutated?

A

Composite Types: Objects, Functions

Example: Adding element to an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Lexical scope mean?

A

Lexical (or local) scope means that in a nested group of functions, the inner functions have access to the variables and other resources of their parent scope.

Lexical scope means that in a nested group of functions, the inner functions have access to the variables and other resources of their parent scope.

This means that the child’s functions are lexically bound to the execution context of their parents.

Lexical scope is sometimes also referred to as static scope.

function grandfather() {
    var name = 'Hammad';
    // 'likes' is not accessible here
    function parent() {
        // 'name' is accessible here
        // 'likes' is not accessible here
        function child() {
            // Innermost level of the scope chain
            // 'name' is also accessible here
            var likes = 'Coding';
        }
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the term Block Scope mean?

A

A block scope is the area within if, switch conditions or for and while loops. Generally speaking, whenever you see {curly brackets}, it is a block. In ES6, const and let keywords allow developers to declare variables in the block scope, which means those variables exist only within the corresponding block.

function foo(){
    if(true){
        var fruit1 = 'apple';        //exist in function scope
        const fruit2 = 'banana';     //exist in block scope
        let fruit3 = 'strawberry';   //exist in block scope
    }
    console.log(fruit1);
    console.log(fruit2);
    console.log(fruit3);
}
foo();
//result:
//apple
//error: fruit2 is not defined
//error: fruit3 is not defined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is .charAt( ) method and what does it do?

A

he String object’s charAt( ) method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string. For example:

const sentence = ‘The quick brown fox jumps over the lazy dog.’;

const index = 4;

console.log(`The character at index ${index} is ${sentence.charAt(index)}`);
// expected output: "The character at index 4 is q"

An integer between 0 and str.length - 1. If the index cannot be converted to the integer or no index is provided, the default is 0, so the first character of str is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is a forEach( ) method? and what is it used for?

A

The forEach() method calls a function for each element in an array.

const fruits = ["apple", "orange", "cherry"];
fruits.forEach(myFunction);
another example: 
const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));

// expected output: "a"
// expected output: "b"
// expected output: "c"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an arrow function? =>

A

An arrow function expression is a compact alternative to a traditional function expression, but is limited and can’t be used in all situations.

// Traditional Anonymous Function
function (a){
  return a + 100;
}

// Arrow Function Break Down

// 1. Remove the word "function" and place arrow between the argument and opening body bracket
(a) => {
  return a + 100;
}
// 2. Remove the body braces and word "return" -- the return is implied.
(a) => a + 100;
// 3. Remove the argument parentheses
a => a + 100;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is the (…) ? called and what is it used for?

A

Its called the spread snytax. The spread syntax is commonly used to make shallow copies of JS objects. Using this operator makes the code concise and enhances its readability.

For Example:
let array1 = [‘h’, ‘e’, ‘l’, ‘l’, ‘o’];
let array2 = […array1];
console.log(array2); [‘h’, ‘e’, ‘l’, ‘l’, ‘o’] // output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Math.floor( ) method? what is it used for?

A

The Math.floor( ) function returns the largest integer less than or equal to a given number.

Syntax: Math.floor(x)

For example:

Math.floor( 45.95); //  45
Math.floor( 45.05); //  45
Math.floor(  4   ); //   4
Math.floor(-45.05); // -46
Math.floor(-45.95); // -46
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Math.ceil( ) method used for? give an example.

A

The Math.ceil( ) function always rounds a number up to the next largest integer.

Syntax: Math.ceil(x)

Example:
console.log(Math.ceil(.95));
// expected output: 1

console.log(Math.ceil(4));
// expected output: 4
console.log(Math.ceil(7.004));
// expected output: 8
console.log(Math.ceil(-7.004));
// expected output: -7
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a set method? and what is it used for?

A

The Set object lets you store unique values of any type, whether primitive values or object references.

let myArray = [‘value1’, ‘value2’, ‘value3’]

// Use the regular Set constructor to transform an Array into a Set
let mySet = new Set(myArray)

mySet.has(‘value1’) // returns true

// Use the spread operator to transform a set into an Array.
console.log([...mySet]) // Will show you exactly the same Array as myArray
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a new method? what is it used for? Give an example

A

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

Syntax: new constructor[ ( [arguments] ) ]

For Example:

function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}

const car1 = new Car(‘Eagle’, ‘Talon TSi’, 1993);

console.log(car1.make);
// expected output: "Eagle"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a reduce( ) method used for? Give me an example.

A
The reduce( ) method executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
Perhaps the easiest-to-understand case for reduce() is to return the sum of all the elements in an array:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Callback Function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

This technique allows a function to call another function

A callback function can run after another function has finished

For Example:

function greeting(name) {
  alert('Hello ' + name);
}
function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a Dom Tree?

A

A DOM tree is a kind of tree whose nodes represent an HTML or XML document’s contents. Each HTML or XML document has a unique DOM tree representation. For example, the following document

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is a Math.max( ) ? What does the method do?

A

The Math.max() function returns the largest of the zero or more numbers given as input parameters, or NaN if any parameter isn’t a number and can’t be converted into one.

For example:

console.log(Math.max(1, 3, 2));
// expected output: 3
console.log(Math.max(-1, -3, -2));
// expected output: -1

const array1 = [1, 3, 2];

console.log(Math.max(...array1));
// expected output: 3
17
Q

What method does concat( ) ( Array. prototype.concat( ) ) do? give me an example.

A

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array. Also helps ensure we dont mutate the provided array by making a copy instead.

For Example:

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]