JavaScript building blocks

2018-05-15 17:26 更新

預備知識

再開始這部分模塊之前, 你應該熟悉基本HTML and css, 還有看完我們之前的模塊, JavaScript first steps.

注解: 如果你在用電腦/平板/其他設備你沒有能力來創(chuàng)建自己的文件,你可以試試在線編輯例如 JSBinThimble.

指南

在代碼中做決定?— 條件
在任何程序語言中, code needs to make decisions and carry out actions accordingly depending on diferent inputs. 例如, 在游戲中, 如果玩家的生命值是0,游戲就結束. 在天氣app中, 如果在早上,則顯示一個太陽升起的圖片; 如果在晚上就顯示星星和月亮. 在這篇文章里我們將探索條件語句結構是怎么在JS里面執(zhí)行的.
循環(huán)
Sometimes you need a task done more than once in a row.例如,查看一整列的名字.在程序中, loops perform this job very well循環(huán)能非常好的處理好這個職責. Here we will look at loop structures in JavaScript.
函數(shù)?— 可重用的代碼塊
Another essential concept in coding is functions. Functions?allow you to store a piece of code that does a single task inside a defined block, and then call that code whenever you need it using a single short command — rather than having to type out the same code multiple times. In this article we'll explore fundamental concepts behind functions such as basic syntax, how to invoke and define functions,?scope, and parameters.
打造自己的函數(shù)
With most of the essential theory dealt with in the previous article, this article provides a practical experience. Here you'll get some practice with building up your own custom function. Along with way, we'll also explain some further useful details of dealing with functions.
函數(shù)返回值
There's one last essential concept for us to discuss in this course, to close our look at functions — return values. Some functions don't return a significant value after completion, but others do. It's important to understand what their?values are, how to make use of them in your code, and how to make your own custom functions return useful values.?
事件介紹
Events are actions or occurrences that happen in the system you are programming, which the system tells you about so you can respond to them in some way if desired. For example if the user clicks a button on a webpage, you might want to respond to that action by displaying an information box. In this final article we will discuss some important concepts surrounding events, and look at how they work in browsers.

評估

以下評估將測試您對上述指南中所述的JavaScript基礎知識的理解。

Image gallery
Now that we've looked at the fundamental building blocks of JavaScript, we'll test your knowledge of loops, functions, conditionals and events by?building a fairly common item you'll see on a lot of websites — a JavaScript-powered image gallery.
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號