得益于 Youtube 的自动字幕功能,现在在上面看一些教程类的视频能听懂百分之七八十,再次感谢伟大的 Google。上周看到了一个 JavaScript 的视频,讲解的简单易懂,逻辑清晰,适合初步了解 JavaScript。
Variables & Data Types
two ways to Place JavaScript
JavaScript can be placed in the <body> and the <head> sections of an HTML page.or you can be place an external files. for example:
|
|
|
|
|
|
Variables
Declare JavaScript Variables with var keyword. Variables:
- can be contain letters ([a-zA-z]), digits ([0-9]), underscore (_), and dollar signs ($).
- Must begin with a letter
- Case senstive (a and A are different variables)
- Reverved words can’t be used
|
|
Array
Two ways to create a array in JavaScript
|
|
And also 2 ways to add element to a Array in JavaScript,
colors[3] = "orange";
but it’s not the best way, we can use the push function
colors.push("orange");
Loops
Four types of loops.
- Four loop
- While loop
- Foreach loop for arrays
|
|
|
|
|
|
Conditions
- if statement
- switch statement
|
|
|
|
Objects
Object literal, we can set a variable and set it to an object.
|
|
Object Constructor is just another way to create a single object
|
|
But if you have some other fruit, you have to do this whole thing for each fruit. we have much simpler way to do this. It’s Constructor Pattern
|
|
Events
Events is one of the most important aspects of learning JavaScript. JavaScript was created to make web pages interactive and dynamic.
|
|
We can change the heading text by clicked the button.
|
|
The onclick is’t the only event we can use. For example onmouseover event
|
|
Forms
JavaScript plays a really big role in form validation and other types of functionality with forms. We can create simple forms with some feild.
|
|
What we want to do is just to show how we can link some events to some of the feilds and do simple form validation.
|
|
if the Firstname is less 3 chars or null, we pop a alert.
