JavaScript Knowledge 2 Flashcards

1
Q

How do you add or remove items to the end of the Array? Give me an example.

A

To add an element to the end of an array, use the push method. To remove items from the end of an array, use the pop method.

let numbers = [1, 2, 3, 4];

numbers. push(5);
console. log(numbers); // should log: [1, 2, 3, 4, 5]

numbers. pop();
console. log(numbers); // should log: [1, 2, 3, 4]

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

How to Incrementor & Decrementor

A

let num = 7;

num = num + 1;
console.log(num); // => 8

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

What is a while loop? Show an example.

A

The while loop starts by evaluating condition. If condition evaluates to true, the code in the code block gets executed. If condition evaluates to false, the code in the code block is not executed and the loop ends.

while (condition) {
  // statement
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a for Loop? describe in technical terms.

A

The for loop consists of three optional expressions, followed by a code block:

initialization - This expression runs before the execution of the first loop, and is usually used to create a counter.
condition - This expression is checked each time before the loop runs. If it evaluates to true, the statement or code in the loop is executed. If it evaluates to false, the loop stops. And if this expression is omitted, it automatically evaluates to true.
finalExpression - This expression is executed after each iteration of the loop. This is usually used to increment a counter, but can be used to decrement a counter instead.

for (initialization; condition; finalExpression) {
  // code
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an Arithmetic Operators?

A

Arithmetic Operators:
There are various Arithmetic Operators –

+ (Addition):
‘+’ operator performs addition on two operands.
Example:
Y = 5 + 5 gives Y = 10

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

What is a Comparison Operators?

A

Comparison Operators:
There are various Comparison Operators in JavaScript –

= = : 
Compares the equality of two operands. If equal then the condition is true otherwise false. 
Example : 
Y = 5 and X = 6
  Y = = X is false.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is String Concatenation>

A

String concatenation is joining strings together. which uses the + operator to concatenate strings.

For example:

console.log(“Hi, “ + firstName);

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

How do you find the length of a string? Give me an example.

A

by adding .length to the end of any string.

for example:

const myString = "Howdy"
console.log(myString.length) // => 5

console.log(“I love JavaScript”.length) // => 17

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

What if you wanted to put a contraction inside of a string? For example, take a look at the folowing code block.

const myString = 'Why doesn't this work';
// => SyntaxError: Unexpected identifier

Looks like the string is getting closed out by our (‘) in doesn’t. What is the solution to this kind of problem?

A

Strings - Escape Sequences (Escaping the character)

Take a look at this example:

const myString = 'Why doesn\'t this work';
console.log(myString) // => 'Why doesn't this work?'

Notice how when we put the () in front of the (‘) it didn’t end our string? This is called escaping the character.

Anytime JavaScript sees a () inside of a string, it knows that the following character has a special meaning. Here is a list of some of the most common escape sequences:

\' => single quote
\" => double quote
\\ => backslash
\n => newline
\r => carriage return
\t => tab
\b => backspace
\f => form feed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a string method? Give me an example.

A

JavaScript methods are actions that can be performed on objects. We already know that all data types in JavaScript are inherently objects, but that also means that each data type comes with its own set of built in methods. A method is essentially a property containing a function definition.

Two common string methods are toUpperCase and toLowerCase. We call these methods similarly to our length property, but in the case of methods, we need to add ( ) to the end of the method name. Here is an example:

const favArtist = “David Bowie”

console. log(favArtist.toUpperCase()) // => “DAVID BOWIE”
console. log(favArtist.toLowerCase()) // => “david bowie”

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

What is a Bracket Notation for strings? What is it used for?

A

Bracket notation is a way to access a specific character in a string. We can do so by simply adding brackets ([]) to the end of our string and placing the index of the character we want to access inbetween those brackets.

let favFood = “tacos”

console. log(favFood[0]) // => “t”
console. log(favFood[2]) // => “c”

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

Comparison Operators

A
< - Less than
> - Greater than
<= - Less than or equal to
>= - Greater than or equal to
== - Is loosely equal to
=== - Is strictly equal to
!= - Is not loosely equal to
!== - Is not strictly equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Type Coercion

A

console. log(10 + 5);
console. log(“10” + 5);
console. log(5 + “10”);

15
‘105’
‘510’

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

How do you add an element at the end of an array?

A

To add an element to the end of an array, use the push method.

let numbers = [1, 2, 3, 4];

numbers. push(5);
console. log(numbers); // should log: [1, 2, 3, 4, 5]

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

How to remove the last element in the array?

A

To remove items from the end of an array, use the pop method.

numbers. pop();
console. log(numbers); // should log: [1, 2, 3, 4]

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