Javascript语法和基础

In this post we will start writing simple Javascript codes and run them on the browser. We will also look comments.

在本文中,我们将开始编写简单的Javascript代码并在浏览器中运行它们。 我们还将查看评论。

两行代码 (Two Lines Of Code)

Our code is below. It is now two line and becoming more complex but not too much for our target.

我们的代码如下。 现在是两行,并且变得更加复杂,但对我们的目标而言并不过分。

console.log("Hello Poftut");
console.log("By Poftut");
  • Here is two JavaScript line ended with ;

    这是两个以结尾JavaScript行

评论 (Comments)

Writing explanations to the code is a good habit for a developer. Comments are used to add explanations to the code and Comments are not interpreted as code. They have no effect the working of code. Below we have added a comment to our single line code.

对开发人员写代码解释是一个好习惯。 注释用于向代码添加说明,注释不解释为代码。 它们对代码的工作没有影响。 下面,我们在单行代码中添加了注释。

//This is single line comment
console.log("Hello Poftut");
/*
This is multi line comment
*/
  • // used for single line comment. Only this this line is a comment

    //用于单行注释。 仅此行是注释

  • /* */ are used multi line comment. Between these all text are just comment

    / * * /用于多行注释。 这些文字之间仅是注释

JavaScript supports writing comments or notes about code without affecting the application. Comments are very useful because it gives more details and explanation to the code.

JavaScript支持在不影响应用程序的情况下编写有关代码的注释或注释。 注释非常有用,因为它为代码提供了更多细节和解释。

//Comment
  • This is a single line comment with //

    这是带有//的单行注释

/*
This is a multiline comment
*/
  • This is a multiline comment. Multi-line comment starts with /* and ends with */ 

    这是多行注释。 多行注释以/ *开头,以* /结束

区分大小写(Case Sensitivity)

Javascript is case-sensitive language. This means keywords, variables etc. all language elements differs with case status. Let me exlain with simple example FOR is different then for. As we see each word case is different. Keep in mind that Html is not case sensitive.

Javascript是区分大小写的语言。 这意味着关键字,变量等。所有语言元素随情况的不同而不同。 让我用简单的例子来解释一下FORFOR不同 我们看到每个单词的大小写都是不同的。 请记住,HTML不区分大小写。

文字 (Literals)

Literals is data values generally used to assign numeric or string values to the variables. Below are some of literals.

文字是通常用于将数字或字符串值分配给变量的数据值。 以下是一些文字。

12
"Hi poftut"
true

关键词 (Keywords)

JavaScript have keywords to operate language logic. For example to loop JavaScript provides while .

JavaScript具有用于操作语言逻辑的关键字。 例如,循环JavaScript提供while

LEARN MORE  What Is DOM (Document Object Model)?
了解更多什么是DOM(文档对象模型)?

分号 (Semicolons)

JavaScript code lines are terminated with semicolons. Semicolons are optional but to make code readable most of the developers use semicolons in their project.

JavaScript代码行以分号终止 分号是可选的,但为了使代码可读,大多数开发人员在其项目中使用分号。

var age=12;
  • JavaScript code line ends with 

    JavaScript代码行以;结尾

将HTML代码添加到HTML页面(Adding JavaScript Code To Html Pages)

For learning purposes we will use Scratchpad but in the real world JavaScript code runs in the html pages. There is two main methods to run JavaScript code in the Html page.

为了学习目的,我们将使用Scratchpad,但在现实世界中,JavaScript代码在html页面中运行。 在Html页面中有两种主要的方法来运行JavaScript代码。

翻译自: https://www.poftut.com/javascript-syntax-basics/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值