Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

JavaScript Notes 2

Uploaded by

gourabdas2128
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

JavaScript Notes 2

Uploaded by

gourabdas2128
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Update <p> using function

<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]
}

here , this is refer to window object(global scope or global context)

var innerWidth = 565;


function windowSize(){
var width = this.innerWidth;
var height = this.innerHeight;
console.log(width,height)
return [width,height]
}
Here, this.innerWidth refer to global var
alert()
alert(message)

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

var num1 = 3433.222;


console.log(num1.toFixed());
console.log(num1.toPrecision());
console.log(num1.toExponential());

Global Objects : Math Object


Logical Operators
If
If else
Switch

You might also like