isNaN("Hello") // Returns true
isNaN(345) // Returns false
isNaN('1') // Returns false, since '1' is converted to Number type which results in 0 ( a number)
isNaN(true) // Returns false, since true converted to Number type results in 1 ( a number)
isNaN(false) // Returns false
isNaN(undefined) // Returns true
first-class
citizens in javascript.function higherOrder(fn) {
fn();
}
higherOrder(function() { console.log("Hello world") });
function higherOrder2() {
return function() {
return "Do something";
}
}
var x = higherOrder2();
x() // Returns "Do something"
document.write("This is \a program");
var x=1, y=2,
z=
x+y;
<html>
<head>
<title>Adding New Elements</title>
<script type="text/javascript">
function addNode() { var newP = document.createElement("p");
var textNode = document.createTextNode(" This is a new text node");
newP.appendChild(textNode); document.getElementById("firstP").appendChild (newP); }
</script>
</head>
<body> <p id="firstP">firstP<p> </body>
</html>
// Declare a global globalVariable = "Test";
this
’ refers to the object it belongs to and gives different values depending upon its usage.var student= {age:20, batch:"ABC"};
delete student.age;
<script language="JavaScript" type="text/javascript" >
<!-- location.href="https://freetimelearning.com/javascript/index.php"; //-->
</script>
pop()
method is similar as the shift()
method but the difference is that the Shift method works at the start of the array. Also the pop()
method take the last element off of the given array and returns it. The array on which is called is then altered. var x; // Now x is undefined
var x = 10; // Now x is a Number
var x = "Name"; // Now x is a String
var I = new object();
Try{
Code
}
Catch(exp){
Code to throw an exception
}
Finally{
Code runs either it finishes successfully or after catch
}
'Navigator.appversion'
is used to find the name of the operating system in the client machine. push
method is used to add or append one or more elements to the end of an Array. Using this method, we can append multiple elements by passing multiple arguments function myfunction() {
"use strict";
var v = "This is a strict mode function";
}
jQuery.noConflict()
. If this has been done, your code can still use $
employing this closure technique, as follows:(function($) { /* jQuery plugin code referencing $ */ } )(jQuery);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document Object Model</title>
</head>
<body>
<div>
<p>
<span></span>
</p>
<label></label>
<input>
</div>
</body>
</html>
document
object in JavaScript represents the DOM. It provides us many methods that we can use to selecting elements to update element contents and many more.alert(document.getElementById('checkbox1').checked);
onDocumentReady
loads the code just after the DOM is loaded. This allows early manipulation of the code.for-in loop
is used to loop through the properties of an object.for (variable name in object){
statement or block to execute
}
var anon = function() {
alert('I am anonymous');
};
anon();​
web-garden
and web-farm
are web hosting systems. The only difference is that web-garden
is a setup that includes many processors in a single server while web-farm
is a larger setup that uses more than one server. fh = fopen(getScriptPath(), 0);
push()
. It adds the desired number of elements to the top of an array. For example :var name = [ "free" ];
name.unshift( "time" );
name.unshift( "learning", "FTL" );
console.log(name);
[" free "," time ", " learning ", " FTL "]
EncodeURI()
is used to convert URL into their hex coding. And DecodeURI()
is used to convert the encoded URL back to normal.<script>
var url="my test.php?name=volkswagen&car=polo";
document.write(encodeURI(url)+ "<br>");
document.write(decodeURI(url));
</script>
my%20test.php?name=volkswagen&car=polo
my test.php?name=volkswagen&car=polo
event.preventDefault()
method prevents the default behavior of an element. If used in a form
element it prevents it from submitting. If used in an anchor
element it prevents it from navigating. If used in a contextmenu
it prevents it from showing or displaying. While the event.stopPropagation()
method stops the propogation of an event or it stops the event from occurring in the bubbling or capturing phase. event.defaultPrevented
property in the event object. It returns a boolean indicating if the event.preventDefault()
was called in a particular element. const falsyValues = ['', 0, null, undefined, NaN, false];
falsy
values are values that when converted to boolean becomes false.prototype
in simplest terms is a blueprint of an object. It is used as a fallback for properties and methods if it does exist in the current object. It's the way to share properties and functionality between objects. It's the core concept around JavaScript's Prototypal Inheritance. const o = {};
console.log(o.toString()); // logs [object Object]
o.toString
method does not exist in the o
object it does not throw an error instead returns a string [object Object]
. When a property does not exist in the object it looks into its prototype and if it still does not exist it looks into the prototype's prototype and so on until it finds a property with the same in the Prototype Chain. The end of the Prototype Chain is the Object.prototype
. console.log(o.toString === Object.prototype.toString); // logs true
// which means we we're looking up the Prototype Chain and it reached
// the Object.prototype and used the "toString" method.
apply
invokes a function specifying the this
or the "owner" object of that function on that time of invocation.const details = {
message: 'Hello World!'
};
function getMessage(){
return this.message;
}
getMessage.apply(details); // returns 'Hello World!'
Function.prototype.call
the only difference is how we pass arguments. In apply
we pass arguments as an array.const person = {
name: "Marko Polo"
};
function greeting(greetingMessage) {
return `${greetingMessage} ${this.name}`;
}
greeting.apply(person, ['Hello']); // returns "Hello Marko Polo!"
call
invokes a function specifying the this
or the "owner" object of that function on that time of invocation.const details = {
message: 'Hello World!'
};
function getMessage(){
return this.message;
}
getMessage.call(details); // returns 'Hello World!'
Function.prototype.apply
the only difference is how we pass arguments. In call
we pass directly the arguments separating them with a comma ,
for every argument.const person = {
name: "Marko Polo"
};
function greeting(greetingMessage) {
return `${greetingMessage} ${this.name}`;
}
greeting.call(person, 'Hello'); // returns "Hello Marko Polo!"
console.log()
accepts a parameter which can be an object, an array or any message. console.log(name);
// here name is object, an array or variable.$('#form').submit(function() {
console.log(‘Your form is submitted successfully!’);
// do something
});
client side technology
, it is mainly used for gives client side validation, but it have lot of features which are given below;var str = "Hello World!";
var n = str.length;
document.getElementById(‘page-title-id’).innerHTML=NewTitle;
document.form[0].submit();
document
or window.document
. document.cookie = “cookiename=Ftl”; expires = date”;
push()
, and to remove an array, pop()
is used.array.push(item1, item2, …, itemX)
object.property_name =value
object.property_name
let user = new Object();
// adding a property
user.name=’ftl’;
user.age =22;
console.log(user);
delete user.age;
var arr1 = [1,2,3]
var arr2 = [4,5,6,7]
var mergedArrays = […arr1, …arr2]
document.write(‘Merged arrays’, mergedArrays)
<img src="demo_image.jpg" onabort="display()">
function abortFunc()
{
alert('Image isn’t loading!');
}
<!DOCTYPE html>
<html>
<body>
<h2>Testing</h2>
<input type="text" onblur="display(this)">
<script>
function display(z) {
z.style.color = "green";
}
</script>
</body>
</html>
onpagehide
event triggers. The visitor can move to another page or click a link after leaving the current web page. An example here displays an alert box when the user tries to leave the page. This happens since onpagehide
event fires when the page is left : <!DOCTYPE html>
<html>
<body onpagehide="display()">
<p>Close the page</p>
<script>
function display() {
alert("It was nice having you here!");
}
</script>
</body>
</html>