JavaScript 最讓我驚訝的部分是它周圍總是有新事物發(fā)生。 而且,無(wú)論您對(duì)它了解多少,您都將始終了解有關(guān)它的新事物。
這些問(wèn)題我收集了很長(zhǎng)時(shí)間。 在大多數(shù)問(wèn)題中,我真的不知道輸出會(huì)是什么,直到我自己嘗試了它們。
所以在這里我將它們記錄下來(lái),以便其他人可以利用它來(lái)學(xué)習(xí)新概念:
輸出:
21{name: “Lydia”} // age won’t be included. Because property defined with defineProperty are non enumerable by default.
輸出:
false // delete operator only deletes a key in objecttrue // when we don’t use any declaration before any variable, it will be treated as a global variable, and will be added as deletable entity in window object.undefined
輸出:
[ { name: “Noren Red”} ] Initially I thought it will log [ null ] because we have initialised person with nullBut in reality, we are only setting new reference to person variable. Previous reference will be used in members arrayIn Short, { name: “Noren Red”} lives in some memory space whose address is X201and this is how referencing is workinglet person = X201const members = [ X201 ]person = null
輸出:
Silver Surfer Because when we return a property, the value of the property is equal to the returned value, not the value set in the constructor function.
輸出:
With the padStart method, we can add padding to the beginning of a string. The value passed to this method is the total length of the string together with the padding. The string “Silver Surfer” has a length of 13. name.padStart(14) inserts 1 space at the start of the string, because 13 + 1 is 13. If the argument passed to the padStart method is smaller than the length of the array, no padding will be added.
輸出:
777If we pass string and number combination to parseInt, what parseInt does is, it check at which position wrong datatype is getting started, if value before the wrong datatype is a valid number, it will return the valid number.
輸出:
1 2 and undefined 3 and undefined 4 If we don’t pass initial value, then by default x will be first value of array, and y will be second value of array.
輸出:
one – [“”, ” is “, ” years old”]two – Thorthree – 1000one – [“hey there, are you amazed”]two – undefinedthree – undefinedIf we use tagged template literals, the value of the first argument is always an array of the string values.The remaining arguments get the values of the passed expressions!
輸出:
1undefined2
輸出:
function // Classes in JS are functions under the hood
關(guān)注七爪網(wǎng),獲取更多APP/小程序/網(wǎng)站源碼資源!