JavaScript--FreeCodeCamp

  1. "=='
    string中如果需要用嵌套引號(hào),可以轉(zhuǎn)義雙引號(hào)也可以交替使用單引號(hào)

想到一個(gè)段子(不無聊的可略過)
問:有沒有什么無意中暴露自己的經(jīng)歷?
答:某日,一妹子問string這單詞什么意思,張口就答字符串。

  1. 如果想通過數(shù)組索引來改變一個(gè)字符串某位置的值是不行的膀懈,需要重新給該字符串賦值,應(yīng)該是值傳遞和引用傳遞的區(qū)別
//錯(cuò)誤示范
var myStr = "Bob";
myStr[0] = "J";
//正確示范
var myStr = "Bob";
myStr[0] = "J";

(太基礎(chǔ)了谨垃,看的我好無聊启搂,感覺馬上可以寫一個(gè)關(guān)于各種教程網(wǎng)站的測(cè)評(píng)了。刘陶。胳赌。)

  1. arr.push(element-value); 在數(shù)組后面拼接element
    arr.pop();
  2. .shift(); function to remove the first item from myArray
    unshift(element-value); adds the element at the beginning of the array.
  3. It is possible to have both local and global variables with the same name. When you do this, the local variable takes precedence over the global variable.
  4. 注意:把函數(shù)返回值賦給變量和把函數(shù)賦給變量不一樣
  5. a queue is an abstract Data Structure where items are kept in order。New items can be added at the back of the queue and old items are taken off from the front of the queue
  6. 也講到了調(diào)用object屬性時(shí)候的兩種方式:一種是.語法匙隔,一種是[]疑苫,區(qū)別在于[]中可以放有空格的字符串,比如obj["hi xy"], 當(dāng)然這個(gè)“hi xy”也可以賦值給一個(gè)變量hi捍掺,然后obj[hi]撼短, 一個(gè)意思
  7. 接下來,能表示某個(gè)屬性挺勿,也就可以改變屬性值或者增加屬性并賦給屬性一個(gè)值曲横,注意,刪除delete obj.prop;
  8. 從switch case表示方法換成object中k-v表示
  9. check if the property of a given object exists or not. .hasOwnProperty(propname) returns true or false.
  10. record collection answer-gist link
    對(duì)英文的需求有點(diǎn)費(fèi)解不瓶,但程序很簡(jiǎn)單
  11. 遍歷obj記得用for in
function lookUpProfile(firstName, prop){
  for(var i = 0; i <contacts.length; i++){
        if (firstName===contacts[i].firstName){
           for(var p in contacts[i]){
             if (prop===p){
               return contacts[i][p];
             }
           }
            return "No such property";
        }  
  }
  return "No such contact";
}
  1. generate a random whole number between 0 and 9
    要whole number用Math.floor()禾嫉,向下取整,down to the closest number.
    Math.floor((Math.random()*10))
    random(): Return a random number between 0 (inclusive) and 1 (exclusive):
  2. 在min到max中選一個(gè)隨機(jī)整數(shù)湃番,注意上面寫的夭织,左閉右開,所以要+1
    return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
  3. 正則/\d+/gi匹配數(shù)字吠撮,g--global \s--space
// This code counts the matches of expression in testString
var andCount = testString.match(expression).length;
  1. To create objects using constructor functions.
    A constructor function is given a capitalized name to make it clear that it is a constructor
    this refers to the new object being created by the constructor
  2. private prop
var Car = function() {
    // this is a private variable
      var speed = 10;
      // these are public methods
      this.accelerate = function(change) {
          speed += change;
      };
      this.decelerate = function() {
          speed -= 5;
      };
      this.getSpeed = function() {
          return speed;
      };
  };
var Bike = function() {
      var gear;
      this.getGear = function(){
        return this.gear;
      };
      this.setGear = function(Gear){
        this.gear = Gear;
      };
    // Only change code below this line.
};
  1. map
var oldArray = [1, 2, 3];
var timesFour = oldArray.map(function(val){  
    return val * 4;
});
console.log(timesFour); // returns [4, 8, 12]
  1. reduce, iterate through an array and condense it into one value.
    比如求所有元素和
var array = [4,5,6,7,8];
var singleVal = 0;
 singleVal = array.reduce(function(previousVal, currentVal) {
  return previousVal + currentVal;
}, 0);
  1. The filter method is used to iterate through an array and filter out elements where a given condition is not true.
var newArray = oldArray.filter(function(val){
      return val<6;
});
  1. sort:
    sort can be passed a compare function as a callback. The compare function should return a negative number if a should be before b, a positive number if a should be after b, or 0 if they are equal.
array.sort(function(a, b) {
      return a - b;
});
//smallest to biggest
  1. array.reverse();
  2. newArray = oldArray.concat(otherArray);
  3. string.split(' ') 參數(shù)為分隔符
  4. arr.join(' ')參數(shù)為連接符

over。下一部分居然是算法題讲竿。泥兰。。


words:

Truncate
quotient
Convert Celsius to Fahrenheit 攝氏度--華氏度

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末题禀,一起剝皮案震驚了整個(gè)濱河市鞋诗,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌迈嘹,老刑警劉巖削彬,帶你破解...
    沈念sama閱讀 219,427評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異秀仲,居然都是意外死亡融痛,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門神僵,熙熙樓的掌柜王于貴愁眉苦臉地迎上來雁刷,“玉大人,你說我怎么就攤上這事保礼∨胬” “怎么了?”我有些...
    開封第一講書人閱讀 165,747評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵炮障,是天一觀的道長(zhǎng)目派。 經(jīng)常有香客問我,道長(zhǎng)胁赢,這世上最難降的妖魔是什么企蹭? 我笑而不...
    開封第一講書人閱讀 58,939評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上练对,老公的妹妹穿的比我還像新娘遍蟋。我一直安慰自己,他們只是感情好螟凭,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評(píng)論 6 392
  • 文/花漫 我一把揭開白布虚青。 她就那樣靜靜地躺著,像睡著了一般螺男。 火紅的嫁衣襯著肌膚如雪棒厘。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,737評(píng)論 1 305
  • 那天下隧,我揣著相機(jī)與錄音奢人,去河邊找鬼摸航。 笑死亚隙,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的玲销。 我是一名探鬼主播土辩,決...
    沈念sama閱讀 40,448評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼支救,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了拷淘?” 一聲冷哼從身側(cè)響起各墨,我...
    開封第一講書人閱讀 39,352評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎启涯,沒想到半個(gè)月后贬堵,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,834評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡结洼,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評(píng)論 3 338
  • 正文 我和宋清朗相戀三年黎做,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片补君。...
    茶點(diǎn)故事閱讀 40,133評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡引几,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出挽铁,到底是詐尸還是另有隱情伟桅,我是刑警寧澤,帶...
    沈念sama閱讀 35,815評(píng)論 5 346
  • 正文 年R本政府宣布叽掘,位于F島的核電站楣铁,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏更扁。R本人自食惡果不足惜盖腕,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評(píng)論 3 331
  • 文/蒙蒙 一赫冬、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧溃列,春花似錦劲厌、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至雅任,卻和暖如春风范,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背沪么。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工硼婿, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人禽车。 一個(gè)月前我還...
    沈念sama閱讀 48,398評(píng)論 3 373
  • 正文 我出身青樓寇漫,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親哭当。 傳聞我的和親對(duì)象是個(gè)殘疾皇子猪腕,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容