js錯誤有幾種型別?

2021-09-23 15:31:38 字數 1236 閱讀 7544

syntaxerror 物件

syntaxerror物件是解析**時發生的語法錯誤。

// 變數名錯誤

var1a;

// uncaught syntaxerror: invalid or unexpected token

// 缺少括號

console.log 'hello');

// uncaught syntaxerror: unexpected string

referenceerror 物件
// 使用乙個不存在的變數

unknownvariable

// uncaught referenceerror: unknownvariable is not defined

// 等號左側不是變數

console.

log()=

1// uncaught referenceerror: invalid left-hand side in assignment

// this 物件不能手動賦值

this=1

// referenceerror: invalid left-hand side in assignment

rangeerror 物件

rangeerror物件是乙個值超出有效範圍時發生的錯誤。主要有幾種情況,一是陣列長度為負數,二是number物件的方法引數超出範圍,以及函式堆疊超過最大值。

// 陣列長度不得為負數

newarray(-

1)// uncaught rangeerror: invalid array length

typeerror 物件

typeerror物件是變數或引數不是預期型別時發生的錯誤。比如,對字串、布林值、數值等原始型別的值使用new命令,就會丟擲這種錯誤,因為new命令的引數應該是乙個建構函式。

new

123// uncaught typeerror: number is not a func

var obj =

;obj.

unknownmethod()

// uncaught typeerror: obj.unknownmethod is not a function

debugger

可以直接在**中寫debugger,頁面sources直接定位到相應位置,更加便捷。

js常用的幾種型別檢測方式

平時資料型別都是清晰明了的,但有些功能函式還是需要用到型別檢測,現總結一下幾種常見的型別檢測方式 typeof instanceof object.prototype.tostring 通常只記得適合基本型別,不要忘了還有函式物件 還有只能大致判斷的object相關的 還有乙個非主流的null 那麼...

物聯網卡有哪幾種型別?

物聯網開卡主要分為兩種 一種是插拔式卡,另一種是貼片式卡 插拔式卡 插拔式卡也叫做mp卡,他在外形上和我們的手機sim卡上差不多的,但是他在一些方面卻比sim卡強大的多,比如 物聯網卡可以適用不同型別的環境場合,不管是在極低的溫度環境還是極高的溫度環境他都能保持正常執行。貼片式卡 貼片式卡也叫ms卡...

MySQL索引,你知道有幾種型別呢?

一 簡介 mysql目前主要有以下幾種索引型別 1.普通索引 2.唯一索引 3.主鍵索引 4.組合索引 5.全文索引 二 語句 create table table name col name data type unique fulltext index key index name asc de...