JavaScript基本知識-W3school-1

本文详细梳理了JavaScript的基础知识点,包括JavaScript的位置、输出方式、大小写敏感、语句、操作符、数据类型、函数、对象、作用域、字符串和字符串方法。强调了document.write()在页面加载后的使用会删除现有HTML,以及区分undefined和null的重要性,并提醒避免将字符串、数字和布尔值声明为对象,以保持代码效率。
摘要由CSDN通过智能技术生成

Javascript基础知识整理

1. javascript where to

a) header or body

<script></script>

b) header:external files

 <script src="myScript.js"></script>

2. JavaScript Output

Writing into an alert box, using window.alert().
Writing into the HTML output using document.write().
Writing into an HTML element, using innerHTML.
Writing into the browser console, using console.log().

** Using document.write() after an HTML document is fully loaded, will delete all existing HTML

3. JavaScript is Case Sensitive

Camel Case: LastName

4. JavaScript Statements

If a JavaScript statement does not fit on one line, the best place to break it, is after an operator:

document.getElementById("demo").innerHTML =
      "Hello Dolly.";

[** You can also break up a code line within a text string with a single backslash:]

document.getElementById("demo").innerHTML = "Hello \
      Dolly!";

[**]The \ method is not a ECMAScript (JavaScript) standard.
Some browsers do not allow spaces behind the \ character.
The safest (but a little slower) way to break a long string is to use string addition(+)

5. JavaScript Operators

a)JavaScript Assignment Operators

Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
** Exponentiation

~
b)JavaScript Comparison and Logical Operators [JS Comparisons]

Operator Description
=== equal value and equal type
!== not equal value or not equal type

~
c)JavaScript Type Operators [JS Type Conversion]

Operator Description
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值