Block statement
var a = 101 { a = 1; } alert(a) //output 1
Conditional Statements
if...else
Executes a group of statements if a logical condition is true. Use the optional else clause to execute another group of statements.
<!DOCTYPE html> <html lang="en"> <head> <meta charset=utf-8> <title>JavaScript if else statement : Example-1</title> </head> <body> <h1 style="color: red">JavaScript : if else statement</h1> <h3>Here the if else statement check whether the input marks is greater than 50 or not.</h3> <hr /> <form name="form1" action ="#"> Input the marks<input type="text" name="text1" value=" " /> <input type="button" value="Marks check" onclick='marksgrade()' /> </form> <script src="if-else-example1.js"></script> </body> </html>
function marksgrade() { if (document.form1.text1.value>50) alert('Marks is greater than 50.'); else alert('Marks is less than or equal to 50.'); }
switch
Syntax
switch (expression){
case label :
statements;
break;
case label :
statements;
break;
... default : statements;
}
Parameters
expression : Value matched against label.
label : An Identifier to be matched against expression.
statements : Group of statements that are executed once if expression matches label.
<!DOCTYPE html> <html lang="en"> <head> <meta charset=utf-8> <title>JavaScript Switch statement : Example-1</title> <link rel="stylesheet" type="text/css" href="example.css"> </head> <body> <h1>JavaScript : switch statement</h1> <form name="form1" action ="#"> Input Grade type : <input type="text" name="text1" value="A" /> <br /><br /> <input type="button" value="Marks check" onclick='marksgrade()' /> </form> <script src="switch-statement-example1.js"></script> </body> </html>
function marksgrade() { grade = document.form1.text1.value; switch (grade) { case 'A+': alert("Marks >= 90"); break; case 'A': alert("Marks [ >= 80 and <90 ]"); break; case 'B+': alert("Marks [ >= 70 and <80 ]"); break; case 'B': alert("Marks [ >= 60 and <70 ]"); break; case 'C': alert("Marks < 60"); break; default: alert("Wrong grade........."); } }
Loop Statements
do while
while
for
break
continue
Object Manipulation Statements
for ... in
Iterates a specified variable over all the properties of an object
and execute one or more statements for each property of the object.
for (variable in object)
{
statements
}
Variable : Variable to iterate over every property of the object and the variable is accessible outside the loop, after completing the loop.
statements : The statement to be executed for each property of an object. For multiple statements within the loop use a block statement ({..}).
function demo() { var key, str1 = ""; // Initialize object. var student = { name : "David Rayy", classname : "V", rollno : 12 }; // Iterate the properties. for(key in student) { str1 = str1+ student[key]; } return(str1); }
Exception Handling Statement
try...catch...throw
window.onload = function() { var empcode = prompt( "Input the Employee code : (Between 3 to 8 characters):", ""); try { if (empcode.length > 8) { throw "error1"; } else if (empcode.length < 3) { throw "error2"; } } catch (err) { if (err == "error1") { alert("The Employee code length exceed 8 characters."); } if (err == "error2") { alert("The Employee code length is less than 3 characters"); } } }
Other Statements
return expression
The return statement returns a value and exits from the current function.
expression : The expression to return. If not present, function does not return a value.
const
A constant is an identifier for a simple value. The value cannot be modified during the script's execution.
The current implementation of const is a Mozilla-specific extension and is not part of ECMAScript 5.
Syntax
const varname1 = value1 , varname2 = value2,... varnameN = valueN
const height = 400; const width = 200;
相关推荐
了解W3C标准: 根据 ECMA-262(ECMAScript)第三版中描述,for-in 语句的属性遍历的顺序是由对象定义时属性的书写顺序决定的。 关于 ECMA-262(ECMAScript)第三版中 for-in 语句的更多信息,请参考 ECMA-262 3rd ...
需要注意的是,尽管Web SQL Database在早期被广泛使用,但它已经不再被W3C推荐作为标准,而是被IndexedDB所取代。IndexedDB提供了更复杂的对象存储和索引功能,且更适合现代Web应用程序的需求。然而,对于理解离线...
<script type="text/javascript" language="javascript"> alert("密码错误或无权限登录,请重新登录"); window.document.location.href="dl-index.jsp"; } else{ request.setCharacterEncoding("UTF-8")...
JDK(Java Development Kit)是Java编程的基础,它的API包含了Java语言的核心类库。这些类库提供了基本的数据类型、异常处理、输入/输出、网络通信、线程管理、集合框架等功能。例如,`java.lang`包下的`String`类...
java.sql.Statement sqlStmt; // SQL语句对象 java.sql.ResultSet sqlRst; // 结果集对象 java.lang.String strCon; // 数据库连接字符串 java.lang.String strSQL; // SQL语句 int intPageSize; // 一页显示的...
复习提纲中的内容涵盖了数据库系统的多个关键知识点,包括但不限于网络通信协议、网页语言、数据访问对象、表达式语言、数据格式、文档对象模型、JavaScript对象表示法、面向对象编程、数据库管理系统以及JDBC驱动...
PreparedStatement ps = con.prepareStatement("SELECT * FROM dtree"); ResultSet rs = ps.executeQuery(); while (rs.next()) { DTree tree = new DTree(); tree.setId(rs.getInt("id")); tree.setPid(rs....
PreparedStatement pre = conn.prepareStatement("select * from myuser where username=? and pwd=?"); pre.setString(1, ub.getName()); pre.setInt(2, ub.getPwd()); ResultSet rs = pre.executeQuery(); if...
pstmt = conn.prepareStatement(sql); pstmt.setString(1, username); pstmt.setString(2, password); rs = pstmt.executeQuery(); if (rs.next()) { return true; } } catch (SQLException e) { e....
23. **JavaScript打开窗口**:使用`window.open`方法可以打开新窗口,如`window.open("http://www.w3schools.com", "window2")`。 这些知识点涵盖了计算机二级考试中可能遇到的多个领域,包括程序设计、数据库操作...
13. **Scripting API**:`javax.script`包允许在Java应用中执行脚本语言,如JavaScript、Groovy等。 14. **JMX(Java Management Extensions)**:提供了管理和监控Java应用程序的工具和API。 以上只是JavaSE6_API...
Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM user WHERE username='" + username + "'"); // 检查结果 int flag = 0; if (rs.next()) { flag = 1; } // ...
Minimum Javascript Skills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 ...
pstmt = conn.prepareStatement(sql); } } catch (SQLException e) { e.printStackTrace(); } return pstmt; } } ``` 在Ajax方面,我们需要使用JavaScript和XMLHttpRequest对象来实现异步请求。具体来说,...