The Global object has properties and methods at the highest level, without a parent object. This means the global properties and functions can be used with all the built-in JavaScript objects.
Properties of the Global object
- Infinity - A numeric value that represents positive/negative infinity
var xn = 1.8976543348623157E+12088;
document.write(xn); // Infinity
- NaN - 'Not-a-Number', represents an object that is not a valid number
var minutes = 61;
if(minutes<0 || minutes>60) {
minutes = Number.NaN;
}
document.write(minutes); // NaN
- undefined - Indicates that a variable has not been assigned a value
var xv;
if(xv==undefined) {
document.write('xv is undefined');
}
Methods of the Global object
- escape('str') - Encodes the non alpha-numeric characters from a string ('str')
var str = 'ab @# 78';
document.write(escape(str)); // ab%20@%23%2078
- eval('str_code') - Evaluates a string and executes it as if it was script code
let str ="document.write('coursesweb.net');";
eval(str); // coursesweb.net
- isFinite(nr) - Returns true if 'nr' is a finite, legal number, otherwise false
document.write(isFinite(123) +'<br>'); // true
document.write(isFinite('string')); // false
- isNaN(nr) - Returns true if 'nr' is an illegal number, otherwise false
document.write(isNaN(123) +'<br>'); // false
document.write(isNaN('string')); // true
- Number(obj) - Converts an object's value to a number
var dat = new Date();
document.write(Number(dat) +'<br>'); // 1296464847762
document.write(Number('0078')); // 78
- parseFloat('str') - Transforms a string into a floating point number
document.write(parseFloat('12.8 pm')); // 12.8
- parseInt('str') - Transforms a string into an integer number
document.write(parseInt('12.8 pm')); // 12
- String(obj) - Converts an object's value to a string
var dat = new Date();
document.write(String(dat)); // Mon Jan 31 2011 11:13:47 GMT+0200 (GTB Standard Time)
- unescape('str') - Decodes a string encoded with escape().
var str = 'ab%20@%23%2078';
document.write(unescape(str)); // ab @# 78
Daily Test with Code Example
HTML
CSS
JavaScript
PHP-MySQL
Which HTML5 tag can be used to embed an external application (SWF, PDF) in web page?
<mark> <embed> <canvas><embed src="flash_game.swf" width="450" height="350" />
Which CSS pseudo-element adds a special style to the first line of a text?
:first-letter :before :first-line#id:first-line {
font-weight: bold;
color: blue;
}
Click on the window object property which gets or sets the URL of current page.
window.location window.self window.statusvar url = window.location;
alert(url);
Indicate the PHP function used to get the contents of a file or page and store it into a string.
fopen() file_put_contents() file_get_contents()$homepage = file_get_contents("http://coursesweb.net/");
echo $homepage;