Home > Web Front-end > JS Tutorial > Sharing experience in getting started with JavaScript

Sharing experience in getting started with JavaScript

黄舟
Release: 2017-07-31 10:26:04
Original
1351 people have browsed it

JavaScript, abbreviated as js, is a programming language used for web pages; it is also very commonly used now. I recall that when I was in college, the school issued a JavaScript textbook. I was really shocked when I saw the thick book. . However, as I learn and deepen, I find that this technology is not that difficult. It is very powerful, flexible and easy to learn.

JavaScript is a scripting language

JavaScript is a lightweight programming language.

JavaScript is programming code that can be inserted into HTML pages.

JavaScript, when inserted into an HTML page, can be executed by all modern browsers.

JavaScript is easy to learn.

Sharing experience in getting started with JavaScript

Recommended learningJavaScript introductory tutorial

1.JavaScript usage

<script> Tag To insert JavaScript into an HTML page, use the <script> tag. </script>

<script> and </script> tell JavaScript where to start and end.

The lines of code between <script> and </script> contain JavaScript:

<script>
alert("我的第一个 JavaScript");
</script>
Copy after login

Course link:http://www.php.cn /code/3511.html


##2.JavaScript syntax

<body>
<p id="demo"></p>
<script>
    document.getElementById("demo").innerHTML = 123e5;
</script>
</body>
Copy after login

Course link: http://www.php.cn/code/3527.html


3.JavaScript data type

<script>
 var carname1="我是双引号";
 var carname2=&#39;我是单引号&#39;;
 var answer1="这是正常的";
 var answer2="我的名字是 &#39;Johnny&#39;";
 var answer3=&#39;我的名字是 "Johnny"&#39;;
 document.write(carname1 + "<br>")
 document.write(carname2 + "<br>")
 document.write(answer1 + "<br>")
 document.write(answer2 + "<br>")
 document.write(answer3 + "<br>")
</script>
Copy after login

Course link: http://www.php.cn/code/3560.html

4. JavaScript Object

<body>
<p>创建 JavaScript 对象。</p>
<p id="demo"></p>
<script>
    var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
    document.getElementById("demo").innerHTML =
            person.firstName + " 现在 " + person.age + " 岁.";
</script>
</body>
Copy after login

##Course link:

http:// www.php.cn/code/3575.html

5.

JavaScript operators: arithmetic operators, assignment operators, string + operators, etc.

<body>
<p>点击按钮计算 x 的值.</p>
<button onclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
function myFunction()
{
y=5;
z=2;
x=y+z;
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
Copy after login

Course link:

http://www.php.cn/code/3597.html

6.

JavaScript conditional statements: If statement, If...else statement, If...else if...else statement

<body>
<p>如果时间早于 20:00,会获得问候 "Good day"。</p>
<button onclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
    function myFunction(){
        var x="";
        var time=new Date().getHours();
        if (time<20){
            x="Good day";
        }
        document.getElementById("demo").innerHTML=x;
    }
</script>
</body>
Copy after login

Course link:

http://www.php.cn/code/3600.html

7.

JavaScript Function Definition

<body>
<p>本例调用的函数会执行一个计算,然后返回结果:</p>
<p id="demo"></p>
<script>
    function myFunction(a,b){
        return a*b;
    }
    document.getElementById("demo").innerHTML=myFunction(4,3);
</script>
</body>
Copy after login

Course link:

http://www.php.cn/code/3643.html

8. Learn to read

JavaScript Manual

. JavaScript does have a lot of function points and knowledge points. If you want to learn it, just follow the manual and learn it one by one. It is best to go through each one, maybe you will use the corresponding things in the future.

The above is the detailed content of Sharing experience in getting started with JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template