官术网_书友最值得收藏!

Chapter 2. Solving Problems Using JavaScript

You have learned how to print something using JavaScript on console in the previous chapter. Now, let's see the fundamentals behind JavaScript syntax, variables, arithmetic operators, and comments.

In the computer world, there is nothing but data. You can read, modify, and create new data; however, anything that isn't data simply does not exist. In JavaScript, we need to handle data to develop a website.

To understand the basic syntax of JavaScript, first of all you need to know that JavaScript is case sensitive. You cannot interchange lower case and upper case letters in JavaScript. Therefore, when dealing with the JavaScript syntax, you need to remember that writing the code is not the only important task, you must also watch the syntax whether it's written correctly.

Let me show you an example. In the previous chapter, you have successfully printed Hello World on your browser using the document.write(); syntax.

What would happen if you wrote Document.write("Hello World");? Yes! It won't run successfully. You will get an error message. This kind of errors is known as Uncaught SyntaxError.

A JavaScript statement is typically written on one line. You may finish your statement with a semicolon or not. It is not mandatory to end a statement with a semicolon. However, it is a good practice to add a semicolon after each statement.

Let's consider the following example:

document.write("Hello");
document.write("World");
document.write("!");

Its output will be as follows:

Note

JavaScript keywords (such as for, while, if, switch, case, and so on) are always in lowercase. The build-in objects (such as Date, Math, Number, and so on) start with uppercase.

主站蜘蛛池模板: 星子县| 临邑县| 高密市| 沈丘县| 惠安县| 德江县| 玛沁县| 洛浦县| 清水河县| 盐津县| 北流市| 攀枝花市| 都江堰市| 余江县| 虹口区| 奇台县| 富源县| 田东县| 砀山县| 武夷山市| 黎川县| 靖州| 武冈市| 屏东市| 茶陵县| 安泽县| 嘉祥县| 西平县| 黎平县| 南皮县| 阜宁县| 汤阴县| 辉县市| 昌都县| 湘潭市| 博兴县| 莱芜市| 太仆寺旗| 岚皋县| 秭归县| 临泉县|