1. 程式人生 > 其它 >Exploiting clickjacking vulnerability to trigger DOM-based XSS:利用點選劫持漏洞觸發基於DOM的XSS

Exploiting clickjacking vulnerability to trigger DOM-based XSS:利用點選劫持漏洞觸發基於DOM的XSS

undefined和null在if語句中,都會被自動轉為false,相等運算子甚至直接報告兩者相等。

if (!undefined) 
    console.log('undefined is false');
// undefined is false

if (!null) 
    console.log('null is false');
// null is false

undefined == null
// true

null表示"沒有物件",即該處不應該有值。典型用法是:

(1) 作為函式的引數,表示該函式的引數不是物件。

(2) 作為物件原型鏈的終點。

Object.getPrototypeOf(Object.prototype)
// null

undefined表示"缺少值",就是此處應該有一個值,但是還沒有定義。典型用法是:

(1)變數被聲明瞭,但沒有賦值時,就等於undefined。

(2) 呼叫函式時,應該提供的引數沒有提供,該引數等於undefined。

(3)物件沒有賦值的屬性,該屬性的值為undefined。

(4)函式沒有返回值時,預設返回undefined。

var i;
i // undefined

function f(x){console.log(x)}
f() // undefined

var  o = new Object();
o.p // undefined

var x = f();
x 
// undefined