Default Flashcards

(45 cards)

1
Q
var myArray = [];
myArray[0] = "Val1";
myArray[2] = "Val3";

What is the value of myArray[1]?

A

undefined

myArray[1] == undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
var customer = {
name: "Lidiya"
};

What is the value of customer.Age?

A

undefined

customer.Age == undefined

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

What operator can be used to check the type of a variable?

A

typeof

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

var myName = “Myro”;

console.log( _______ myName);

What operator should be used in front of myName in the second line to get the type of myName to show in the console?

A

typeof

console.log( typeof myName);

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

var myAge = 38 ;

console.log(typeof myAge);

What will be displayed in the console?

A

number

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

When is null used in JavaScript?

A

In places where the object should be but can’t be created of found. For example, if you try the following:

var myObj = document.getElementById(“elm1”);

and elm1 id does not exist, myObj will be set to null.

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

When is undefined used in JavaScript?

A

For the variable that is not initialised, an object’s missing property or a missing value of an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
var test10 = null;
console.log(typeof test);

What will be output to console?

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
var test = 0/0;
console.log(test);

What will be output to console?

A

NaN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
var test = "food" * 10;
console.log(test);

What will be output to console?

A

NaN

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

How to check whether something has NaN value?

A

isNan() function

For example:

var myNum = 0;
if(isNaN(myNum)){
    //some code
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
var test11 = 0 / 0;
console.log(typeof test11);

What will be output to console?

A

number

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

What happens when you compare a string to a number?

99 == “bob”

A

The string is converted to a number and then two numbers are compared. In this case “bob” converted to a number is NaN and 99 not equals to NaN.

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

What number does boolean value “true” convert to?

A

1

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

What number does boolean value “false” convert to?

A

0

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

Ho will this comparison proceed?

1 == true

A

“true” will be converted to number 1 and compared to 1. The result will be true

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

How will this comparison proceed?

“1” == true

A
  1. “true” will be converted to number 1
    “1” == 1
  2. “1” will be converted to number
    1 == 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

is this true?

undefined == null

A

Yes! That is the rule in JavaScript.

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

What number is the empty string converted to in this case?

1 == “”

A

”” is converted to number 0

20
Q

How will this comparison proceed?

“true” == true

A
  1. boolean true will be converted to a number 1
  2. “true” will be attempted to be converted to a number and the left side will get a value of NaN
  3. NaN == 1? false
21
Q

Is there a !== operator?

22
Q
var add = "4" + 3;
console.log(add);

What will be output to console?

A

43

”+” converts the number into the string first, them concatenates

23
Q
var add = 78+ "2";
console.log(add);

What will be output to console?

A

782

”+” converts the number into the string first, them concatenates

24
Q
var multi= 4 * "2";
console.log(multi);

What will be output to console?

A

8

In case of all arithmetic operators besides “+”, the string is first converted to number and then the operation is performed.

25
``` var minus= "7" - 2; console.log(minus); ``` What will be output to console?
5 In case of all arithmetic operators besides "+", the string is first converted to number and then the operation is performed.
26
``` var order = 1 + 2 + " pizzas"; console.log(order); ``` What will be output to console?
3 pizzas "+" operator has left-to-right associativity
27
``` var order = 1 + (2 + " pizzas"); console.log(order); ``` What will be output to console?
12 pizzas concatenating string with number always converts number to string first
28
What function is used to convert string to number?
Number() For example: var num = 3 + Number("4"); num will be set to 7
29
``` var res= "Result: " + 10/2; console.log(res); ``` What will be output to console?
Result: 5 ``` The division will happen first because of the operators' order of precedence: "Result: " + (10/2) | | V "Result: " + 5 ```
30
What are 5 falsey values in JavaScript?
1. undefined 2. null 3. 0 (zero) 4. empty string 5. NaN
31
``` if([]){ console.log("This is true"); } else{ console.log("This is false"); } ``` What will be output to console?
This is true. [] is an empty array and it is not one of the falsey values.
32
``` if(" "){ console.log("This is true"); } else{ console.log("This is false"); } ``` What will be output to console? Note that this is a string with one space in it.
This is true. This is a non-empty string, therefore it is truthy.
33
var uppCase = "HELLO"; How to put a text in variable uppCase into lower case?
use toLowerCase() methodof a string type, like so: alert(uppCase.toLowerCase());
34
var emailVar = "hello@gmail.com"; How can we get a string containing "@" from variable emailVar?
var newStr = emailVar.charAt(5);
35
``` var strVar = "I like movies"; console.log(strVar.indexOf("mov")); ``` What will be output to console?
7 indexOf() function of the string object returns the index of of the first character of the first occurrence of the argument.
36
``` var strVar = "I like to move it move it."; console.log(strVar.indexOf("mov")); ``` What will be output to console?
10 Although, indexOf() returns the index of the first character of the argument, it only returns the index of the first character in the FIRST OCCURRENCE of the argument.
37
var strVar = "I like to move it move it."; How can you get the index of the second occurrence of "move" in strVar?
Use indexOf() method of string object with the second parameter. Second parameter is an integer that indicates where in the string should the search begin. console.log(strVar.indexOf("mov", 11)); Guess what would be output to console?
38
``` var strVar = "I like to move it move it."; console.log(strVar.indexOf("bleh")); ``` What will be output to console?
-1 indexOf() method returns -1 if the string is not found
39
var strVar = "car/house/road"; How will you extract "house" string from strVar variable?
var extracted = strVar.substring(4,9);
40
var strVar = "car/house/road"; How will you extract "house/road" string from strVar variable?
var extracted = strVar.substring(4); substring() method of string object, if used with only one parameter, returns the string that begins at the first parameter's index and ends at the end of the string.
41
var people = "Jack,Jane,John"; What method of the sting object can we use to put each person into an element in array in one operation?
split() var personArr = people.split(",");
42
What are two methods of string object that can be used to get a portion of the string from the original string?
1. slice() | 2. substring()
43
What method of string object is used to get the last index of a substring in the original string?
lastIndexOf()
44
What method of string object is used to add another string to the current one?
concat()
45
How can you get a user input from a browser dialogue?
prompt() method. This is window's method. You can use either prompt() or window.prompt(). var userInput = prompt("What is your name?");