JavaScript Notes 2
JavaScript Notes 2
<body>
<div id="parent-id">
<p>hello word1</p>
<p id="test1" onclick="changeText('Hello World')">hello word2</p>
<p>hello word3</p>
<p>hello word4</p>
</div>
<script>
function changeText(text) {
var text_p = document.getElementById("test1");
text_p.textContent = text
}
</script>
</body>
Anonymous Function
this Keyword
function windowSize(){
var width = this.innerWidth;
var height = this.innerHeight;
console.log(width,height)
return [width,height]
}
open()
open(url)
open(url, target)
open(url, target, windowFeatures)
window.alert("hello")
window.open("https://www.mozilla.org/", "mozillaTab");
window.open("https://www.mozilla.org/", "mozillaWindow", "popup");
const windowFeatures = "left=100,top=100,width=320,height=320";
const handle = window.open("https://www.mozilla.org/",
"mozillaWindow", windowFeatures);
if (!handle) {
// The window wasn't allowed to open
// This is likely caused by built-in popup blockers.
// …
}
alert(window.location)
String
Global Object Number Object
var num = NaN;
console.log(isNaN(num));//True
num = 839/'a';
console.log(isNaN(num));//True
num = 9898;
console.log(isNaN(num));//False