JavaScript Flashcards
What is the result of below
“apple”.length
“5”
Remember, index does not matter here. It just count the number of words
Also, .length method cannot be applied in array.
how many words is counted if there is \n inside a string
1 only, not two
in Javascript, what will console.log (0.2+0.4) result in?
0.6000000000000001, the reason is computer in binary digits, 在電腦的角度, 這些小數點是除不盡的. 所以衹要電腦是計算小數點, 都會有不精准的情況, 所以在計算價錢的時候要特別注意
const sentence = “Teck Academy is good”
console.log(sentence.substring(sentence.length-4))
What is the purpose of substring. what will come out
the argument in substring is that what LAST number of index of string the computer will show
what is NaN
“not a number” that’s a bug
how to use math method in Javascipt
console.log(Math.max(1,2,3,4,5))
how to eliminate digitial number or usye the digitial number to round up to interger
Math.floor(1.xxx) = 1
Math.ceiling
Math.round
Before Node.js is invented, where was Javascript run?
only on web brower
when is camel case format used? And how?
We normally name function using the camel case format. The name normally starts with a verb because a function is normally a function on its own.
// Correct function sumOfArray(){ }
// Incorrect function sum_of_array(){ }
// Incorrect function sumofarray(){ }
What is the difference between expression and statement?
The correct answer is: if-else block are statements while ternary operators condition ? true-value: false-value is expression.
what is the symbol of END operator in Boolean. What are OR and NOT
&&, ||, !
comparsion operator >=口號, and !=
大於或等於
can 15% be 0.015 in Javascript?
NO. It does not exist and give error
Uncaught c:\Users\C\Documents\tacky_js_fund\001.js:69
can I declare x = 1, two times
no, the second time just declare “x = 1”
how to add item in array
array.push(XXX), it will go to the last index of the array
how to remove the last item in array
array(/llzlazlease z
two methods that can access the value in object thought key? What are they?
chris = {‘height’ : 180}
chris[‘height’]
OR
chris.height
SPECIAL case in the key of object,
if in the key of object, there is for exmaple,
“living place” or “living-place”
can I type chris.living-place?
then you cant use
chris.living-place, because it just cant, computer will think it is minus sign
can you add a unnecessary comma after the last item in array and object
yes you can, there wont be error, also this is convenient for you to copy and paste paste
in object, what if you want to delete one key with its value?
you just write
delete chris[key]
保持隊形
就算空了也要給個空的array
what is good structure if I want to limit the while loop to the number of array?
while (n< nameList.length) THIS
n = 0 while (n< nameList.length){ if (nameList[n].height > 170){ console.log(nameList[n].name) } n += 1
arrry add and delete things?
// To add a new element to the end of the array arr.push(5);
// To remove a element from the end of the array arr.pop();
// To add a new element to the start of the array arr.unshift(0);
// To remove a element from the start of the array arr.shift();
function return發生多少次
return 只會發生一次, 其他return就會被忽略