JavaScript语法快速学习

资料来源于:B站尚硅谷JavaWeb教程(全新技术栈,全程实战) ,本人才疏学浅,记录其笔记以供他日回顾
视频链接

知识点

<!--
Javascript : 客户端的一个脚本语言
js是一门弱类型的语言 , 变量的数据类型由后面赋的值的类型决定

个人总结:
1.js的语法和java很类似,它的类型由一个var来代表,比如java中会有int、String,但是js中都可以用var来代替。
2.alert();方法中会打印一些东西,比如
  var str = "hello world";
  alert(typeof str)会打印出str的类型 ,
  且也可以是打印类中的参数,见下面的示例代码
3.js的方法相比较java中的方法,格式为:
  function(参数) {
      方法体

  }
 同一个方法可能有返回值,也可能没有返回值,比较随性。

-->

示例代码

<html>
	<head>
		<meta charset="utf-8">
		<script language="javascript">
			// String str = "hello world" ;
			
			/*
			var str = "hello world";
			alert(typeof str);
			str = 9999 ;
			alert(typeof str);
			*/
			/*
			var person = new Object();
			person.pid = "p001";
			person.pname="鸠摩智";

			alert(person.pid+"_"+person.pname);
			*/
			//java 方法
			public String hello(String name){
				return "hello to " + name ;
			}

			//js 方法
			function hello(num1 , num2 , name){
				if(num1>num2){
					return "hello to" + name ;
				}else{
					alert("HELLO");
				}
			}


		</script>
	</head>
	<body>
		
	</body>
</html>

posted @ 2023-02-24 12:19  飞哥传书  阅读(25)  评论(0)    收藏  举报