Default Flashcards
(45 cards)
var myArray = []; myArray[0] = "Val1"; myArray[2] = "Val3";
What is the value of myArray[1]?
undefined
myArray[1] == undefined
var customer = { name: "Lidiya" };
What is the value of customer.Age?
undefined
customer.Age == undefined
What operator can be used to check the type of a variable?
typeof
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?
typeof
console.log( typeof myName);
var myAge = 38 ;
console.log(typeof myAge);
What will be displayed in the console?
number
When is null used in JavaScript?
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.
When is undefined used in JavaScript?
For the variable that is not initialised, an object’s missing property or a missing value of an array.
var test10 = null; console.log(typeof test);
What will be output to console?
object
var test = 0/0; console.log(test);
What will be output to console?
NaN
var test = "food" * 10; console.log(test);
What will be output to console?
NaN
How to check whether something has NaN value?
isNan() function
For example:
var myNum = 0; if(isNaN(myNum)){ //some code }
var test11 = 0 / 0; console.log(typeof test11);
What will be output to console?
number
What happens when you compare a string to a number?
99 == “bob”
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.
What number does boolean value “true” convert to?
1
What number does boolean value “false” convert to?
0
Ho will this comparison proceed?
1 == true
“true” will be converted to number 1 and compared to 1. The result will be true
How will this comparison proceed?
“1” == true
- “true” will be converted to number 1
“1” == 1 - “1” will be converted to number
1 == 1
is this true?
undefined == null
Yes! That is the rule in JavaScript.
What number is the empty string converted to in this case?
1 == “”
”” is converted to number 0
How will this comparison proceed?
“true” == true
- boolean true will be converted to a number 1
- “true” will be attempted to be converted to a number and the left side will get a value of NaN
- NaN == 1? false
Is there a !== operator?
Yes!
var add = "4" + 3; console.log(add);
What will be output to console?
43
”+” converts the number into the string first, them concatenates
var add = 78+ "2"; console.log(add);
What will be output to console?
782
”+” converts the number into the string first, them concatenates
var multi= 4 * "2"; console.log(multi);
What will be output to console?
8
In case of all arithmetic operators besides “+”, the string is first converted to number and then the operation is performed.