JavaScript 的语法

从零理解Brep:用Python玩转3D建模的边界表示法(附OpenCASCADE示例) 本文深入解析了边界表示法(Brep)在3D建模中的应用,通过Python和OpenCASCADE的实战示例,详细介绍了Brep的核心数据结构、布尔运算、网格转换及3D打印优化技巧。适合CAD设计、3D打印和计算机图形学领域的开发者学习与实践。 阅读详情
 

JavaScript 的语法

JavaScript statements consist of keywords used with the appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semi-colon.

Syntax conventions: All keywords in syntax statements are in bold. Words in italics represent user-defined names or statements. Any portions enclosed in square brackets, i.e. [ and ], are optional. {statements} indicates a block of statements, which can consist of a single statement or multiple statements delimited by a curly braces.

The following statements are available in JavaScript:


break statement

The break statement terminates the current while or for loop and transfers program control to the statement following the terminated loop.

Syntax

break

Examples

The following function has a break statement that terminates the while loop when i is 3, and then returns the value 3 * x.

function func(x) { 
    var i = 0; 
    while (i < 6) { 
        if (i == 3)  
            break;
        i++;
    }
    return i*x; 
} 

comment statement

Comments are notations by the author to explain what the script does, and they are ignored by the interpreter. JavaScript supports Java-style comments:

  • Comments on a single line are preceded by a double-slash (//).
  • Comments that span multiple lines are preceded by a /* and followed by a */.

    Syntax

    1. // comment text 
    2. /* multiple line comment text */

    Examples

    // This is a single-line comment.
    
    
    /* This is a multiple-line comment. It can be of any length, and you can put whatever you want here. */

    continue statement

    The continue statement terminates execution of the block of statements in a while or for loop, and continues execution of the loop with the next iteration. In contrast to the break statement, it does not terminate the execution of the loop entirely: instead,

    • In a while loop it jumps back to the condition.
    • In a for loop it jumps to the update expression.

    Syntax

    continue

    Examples

    The following example shows a while loop that has a continue statement that executes when the value of i is 3. Thus, n takes on the values 1, 3, 7, and 12.

    i = 0; 
    n = 0; 
    while (i < 5) { 
        i++; 
        if (i == 3) 
            continue;  
        n += i;
    } 
    

    for statement

    A for loop consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a block of statements executed in the loop. The parts of the for statement are:

    • The initial expression, generally used to initialize a counter variable. This statement may optionally declare new variables with the var keyword. This expression is optional.
    • The condition that is is evaluated on each pass through the loop. If this condition is true, the statements in the succeeding block are performed. This conditional test is optional. If omitted, then the condition always evaluates to true.
    • An update expression generally used to update or increment the counter variable. This expression is optional.
    • A block of statements that are executed as long as the condition is true. This can be a single statement or multiple statements. Although not required, it is good practice to indent these statements four spaces from the beginning of the for statement.

    Syntax

    for ([initial expression]; [condition]; [update expression]) {
        statements
    }
    initial expression = statement | variable declartion
    

    Examples

    This simple for statement starts by declaring the variable i and initializing it to zero. It checks that i is less than nine, and performs the two succeeding statements, and increments i by one after each pass through the loop.

    for (var i = 0; i < 9; i++) { 
        n += i;
        myfunc(n);
    }
    

    for...in statement

    The for statement iterates variable var over all the properties of object obj. For each distinct property, it executes the statements in statements.

    Syntax

    for (var in obj) { 
        statements }

    Examples

    The following function takes as its argument an object and the object's name. It then iterates over all the object's properties and returns a string that lists the property names and their values.

    function dump_props(obj, obj_name) { 
        var result = "", i = "";
        for (i in obj)
            result += obj_name + "." + i + " = " + obj[i] + "/n";
        return result;
    } 

    function statement

    The function statement declares a JavaScript function name with the specified parameters param. To return a value, the function must have a return statement that specifies the value to return. You cannot nest a function statement in another statement or in itself.

    All parameters are passed to functions, by value. In other words, the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function.

    Syntax

    function name([param] [, param] [..., param]) {
        statements }

    Examples

    //This function returns the total dollar amount of sales, when 
    //given the number of units sold of products a, b, and c.
    function calc_sales(units_a, units_b, units_c) {
        return units_a*79 + units_b*129 + units_c*699
    }

    if...else statement

    The if...else statement is a conditional statement that executes the statements in statements if condition is true. In the optional else clause, it executes the statements in else statements if condition is false. These may be any JavaScript statements, including further nested if statements.

    Syntax

    if (condition) {
        statements
    } [else {
        else statements
    }]

    Examples

    if ( cipher_char == from_char ) {
        result = result + to_char; 
        x++
    } else  
        result = result + clear_char; 
     

    return statement

    The return statement specifies the value to be returned by a function.

    Syntax

    return expression;

    Examples

    The following simple function returns the square of its argument, x, where x is an number.

    function square( x ) { 
        return x * x; 
    } 

    var statement

    The var statement declares a variable varname, optionally initializing it to have value. The variable name varname can be any legal identifier, and value can be any legal expression. The scope of a variable is the current function or, for variables declared outside a function, the current application.

    Using var outside a function is optional; you can declare a variable by simply assigning it a value. However, it is good style to use var, and it is neccessary in functions if there is a global variable of the same name. So, in general, it is a good idea to always use var, but you should definitely use it when declaring a local variable in a function, to ensure that any global variable of the same name does not override it.

    Syntax

    var varname [= value] [..., varname [= value] ]
    

    Examples

    var num_hits = 0, cust_no = 0


    while statement

    The while statement is a loop that evaluates the expression condition,and if it is true, executes statements. It then repeats this process, as long as condition is true. When condition evaluates to false, execution continues with the next statement following the statements.

    Although not required, it is good practice to indent the statements a while loop four spaces from the beginning of the for statement.

    Syntax

    while (condition) {
        statements
    }
    

    Examples

    The following simple while loop iterates as long as n is less than three. Each iteration, it increments n and adds it to x. Therefore, x and n take on the following values

    • After first pass: x = 1 and n = 1
    • After second pass: x = 2 and n = 3
    • After third pass: x = 3 and n = 6

    After completing the third pass, the condition n < 3 is no longer true, so the loop terminates.

    n = 0; 
    x = 0; 
    while( n < 3 ) { 
        n ++; x += n; 
    } 

    with statement

    The with statement establishes object as the default object for the statements. Any property references without an object are then assumed to be for object. Note that the parentheses are required around object.

    Syntax

    with (object){ 
         statements 
    }

    Examples

    with (Math) { 
        a = PI * r*r
        x = r * cos(theta)
        y = r * sin(theta) 
    }
    
利用Solidworks生成(抽取)流体通道(流道)模型 如何利用Solidworks生成流体通道模型? 在仿真计算中,尤其是流体的仿真计算中,经常涉及到流体通道的建模,而我们拿到最直接的三维结构图往往是真实的实体结构,流体通道则是实体结构的中空部分,那么在拥有实体结构的情况下,如何利用Solidworks快速建立流体通道实体结构呢? ... 阅读详情

相关推荐

一文看懂分布式存储架构

目录一、集中存储结构二、分布式存储1 、分布式存储的兴起2 、分布式存储的重要性3 、分布式存储的种类和比较三、分布式理论浅析1 、一致性和可用性2 、数据分布3 、复制4 、分布式协议5、跨机房部署四、分布式文件系统1、 Google 文件系统( GFS )2、 Taobao 文件系统( TFS )3、 Fackbook Haystack 文件系统4、 CDN 内容分发网络五、分布式键值系统1、 Amazon Dynamo2、 Taobao Tiar3、 ETCD4 、产品选型比较( Etcd , Zoo

weixin_70730532的博客 2万+

【JavaScript用法】JavaScript(JS)的基本语法(JS数据类型,JS变量,JS运算符,JS流程控制语句)

JavaScript(JS)的基本语法 目录 JavaScript(JS)的基本语法 一. 与html结合方式 二. 注释 三. 数据类型: 四. 变量 五. 运算符(和Java有点类似) 六. 流程控制语句(和JAVA类似): 七. JS特殊语法: 一. 与html结合方式 1. 内部JS:定义<script>,标签体内容就是js代码(...

No8g攻城狮的博客 5108

抖音小游戏上架避坑指南:从软著申请到ICP备案全流程解析

本文详细解析了抖音小游戏上架前必须完成的软著申请和ICP备案全流程,提供了清晰的时间线规划与实操避坑指南。文章重点阐述了个人与企业备案的区别、材料准备要点以及平台审核常见问题,旨在帮助独立开发者和小团队高效、合规地完成游戏上架,避免在行政流程中延误项目。

weixin_29276847的博客 1660

JS(JavaScript)基本语法以及其它语法

JS

qq_43737870的博客 1622

2025-03-21(DS复习): Databricks 的技术架构

Databricks 的技术架构以 ​为核心,构建了一套高度集成、可扩展且支持多云环境的统一分析平台。其架构设计注重存储与计算的深度融合,并通过丰富的服务层功能简化了数据工程、机器学习和数据科学的工作流。

baidu_24377669的博客 1432

python中frida的安装+frida-server(雷电模拟器)保姆级安装教程

frida的安装,安卓逆向,adb

2301_80224944的博客 4605

JS(JavaScript)入门语法,语法+示例,非常详细!!!

JS(JavaScript)入门语法,语法+示例,非常详细!!!

m0_62951223的博客 631

解决/usr/lib64/libstdc++.so.6和/lib64/libc.so.6版本过低问题

在CentOS7.0中编译好MySQL5.7.14之后,然后在CentOS6.5中初始化MySQL,执行:/usr/local/mysql/bin/mysqld --version出现如下问题:./bin/mysqld: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./bin/mysqld)

poxiaonie的博客 2万+

JavaScript系列之JS入门基本语法

JavaScript系列之JS入门/基本语法 01 JavaScript入门 JavaScript是一门基于对象和事件驱动的,并具有安全性能的脚本语言 常见误区:我们通常见名猜意会认为JavaScript与Java有所联系,而事实上,JavaScript除了语法上有点像Java,其他部分基本上没啥关系。 JavaScript发展过程中的关键节点 1995年,网景公司的Brendan Eich只...

DOGIOOH的博客 357

IBM AC922 8335-GTW 安装linux,CentOS,ubuntu,RHEL各种坑

AC922

u011970286的专栏 929

使用C# HslCommunication库实现三菱PLC通信(含完整代码示例)

在工业自动化开发中,上位机与PLC的通信是关键环节。HslCommunication库是一个开源的.NET工业通信库,支持三菱、西门子、欧姆龙等多个品牌PLC的通信协议。本文将演示如何通过库实现C#程序与三菱PLC的通信,并提供完整的代码示例。

StevenChen的博客 2300

vim-js:为JavaScript开发者带来卓越的语法高亮体验

vim-js:为JavaScript开发者带来卓越的语法高亮体验 项目介绍 vim-js 是一款专为 Vim 编辑器设计的 JavaScript 语法高亮插件,同时提供对 Flow.js 的支持。这款插件不仅兼容现代 JavaScript 的新特性,还支持 JSDoc 语法,为开发者提供更加准确和个性化的语法高亮体验。 项目技术分析 vim-js 插件针对以下现代 JavaScript 特性提供了...

gitblog_01137的博客 688

【2025最新版】间接平差——以水准网平差为例 (python详细过程版)

水准网间接平差的python代码实现。博客长期更新,本文最新更新时间为:2025年5月20日。

点云侠的博客 1705

【JavaScript】JS核心语法及函数

JavaScript 是一种基于对象和事件驱动的、并具有安全性能的脚本语言。

m0_66584716的博客 1407

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

JavaScript(JS)的基础语法总结

JavaScript(JS)的基础语法总结

yunAike的博客 1079

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

javascript-js基础语法

js基础语法 xamp:强大的建站集成软件包 分为:apache、mysql、php、perl 1、 在HTML中作用: (1)      可以控制DOM (2)      可以控制CSS (3)      用户交互 (4)      事件编程 (5)      网络通讯 例子一:弹框: 方法1: &lt;input type="button"value="弹框" onCli...

张新丁 654

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

什么是JavaScript;JS的基本语法

什么是JavaScript;JS能做什么;JS 与 ECMAScript 的关系;JS的基本语法;写入js代码的方法;语句;变量

L_ABCyl的博客 365

【JavaScript】JS的基本语法

JS是一种脚本语言,直接插入到HTML文档中即可 JS语句要放在<script></script>标签中,网页加载时就会自动加载该标签中的内容 内联: JS代码放在<head>和<body>中均可,但为了确保网页正常运行,一般将JS代码放在<head>中或是放在文档的最底部 外联: 诸如此类:<script src="myScrip...

奷姀的谜之练习 390

javascript(js)基础语法

1如何引入js: 三种方式: 方式一: 把js代码写在html的某个标签中 方式二: 把js代码写在html文件中元素中的 方式三: -把js代码写在专门的js文件中 test.js 文件内容: function bb(){ alert(“哈哈 bb方法”); } 在html文件中的head元素中引入js文件 在html的head元素中中可以引入多个js文件 但每个script标记只能引入一个...

weixin_45386575的博客 252

JavaScript基础(JS基本语法)

1.JavaScript简介 (1)JavaScript概述 JavaScript是一个基于对象的、事件驱动的、解释型的编程语言 (2)JavaScript特点 JavaScript特点:基于对戏那个、事件驱动、跨平台、解释型 ·基于对象:JavaScript语言中它提供了大量的对象可以直接使用,提高程序开发效率 ·事件驱动:可以让项目和用户的操作之间产生一些良好的交互 ·跨平台:不通过的操作系统上都...

weixin_44978043的博客 303

JavaScript之Highlight.js语法高亮显示神器集成说明

JavaScript之Highlight.js语法高亮显示神器集成说明

yuanjinshenglife的专栏 1万+

JS 入门之 JavaScript 概述和基础语法

JavaScript是一种运行于JavaScript解释器/引擎中的解释型脚本语言。

PSG_li的博客 629

JavaScript--【JS】基础语法

JS基础语法(一) JS的引入 JS代码应该写在什么地方,学过的所有的代码都是一种语言,不同的语言对应的语言文件后缀名不一样,所以在html文件中的所有数据计算机默认以对待html数据的处理方式进行处理。如果需要使用js和html的搭配就需要考虑将js代码写在什么地方。 1.行内js 将js代码直接写在html标签内的某个属性值里面 <input type="button" value="点击" onclick="alert('hellow')"> 2.内嵌js 在html文件里面的某个地方

ZJie0的博客 317

highlight.js:JavaScript语法高亮库的全面介绍

highlight.js:JavaScript语法高亮库的全面介绍 Highlight.js 是一个功能强大的零依赖开源 JavaScript 语法高亮库,支持超过 180 种编程语言和标记语言,具备智能语言自动检测功能。本文将从项目架构、核心特性、多语言支持、零依赖设计等方面进行全面深入的解析,帮助开发者更好地理解和使用这一强大的语法高亮工具。 highlight.js项目概述与核心特性 Hig...

gitblog_00890的博客 500

JS--JavaScript语法基础

JavaScript语法基础 使用JS操作网页(DOM) 使用JS操作浏览器(BOM) 与HTML和CSS的不同: html: 负责了一个页面的结构. css: 负责了一个页面的样式。 javascript: 负责与用户进行交互。 如何编写javascript的代码。 方式1:可以使用<script>标签体内进行编写。 格式: <script type="text/javascript"> js代码;; </script&gt

JinMujun的博客 226

JavaScript基础语法详解

函数是一段可以重复使用的代码块。在 JavaScript 中,可以使用functionJavaScript 是一种功能强大的语言,它通过基础语法提供了丰富的功能,使得网页能够实现动态交互和复杂的逻辑处理。掌握这些基础语法是学习 JavaScript 的第一步,也是成为一名优秀前端开发者的基础。版权声明:本博客内容为原创,转载请保留原文链接及作者信息。参考文章JavaScript语法基础(超详细,看这一篇就够了)-CSDN博客清华大学出版社-图书详情-《JavaScript 基础语法详解》

ning的博客 2379
上一篇: Javascript的保留字
下一篇: JavaScript学习 第 一 章
spirityj
博客等级 码龄22年 0粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址