jQuery Basic Overview
As we know that jQuery is a framework built using JavaScript capabilities. So, we can use all the functions and other capabilities available in JavaScript. In this article it would explain most basic concepts but frequently used in jQuery:
String In jQuery
A string
in JavaScript/jQuery is an immutable object that contains none, one or many characters.
Following are the valid examples of a JavaScript/jQuery String −
"This is JavaScript/jQuery String" 'This is JavaScript String' 'This is "really" a JavaScript/jQuery String' "This is 'really' a JavaScript/jQuery String"
Numbers In jQuery
Numbers in JavaScript are double-precision 64-bit format IEEE 754 values. They are immutable, just as strings. Following are the valid examples of a JavaScript/jQuery Numbers −
5350 120.27 0.26
Boolean In jQuery
A boolean in JavaScript/jQuery can be either true or false. If a number is zero, it defaults to false. If an empty string defaults to false Following are the valid examples of a JavaScript Boolean −
true // true false // false 0 // false 1 // true "" // false "hello" // true
Objects In jQuery
JavaScript/jQuery supports Object concept very well. We can create an object using the object literal as follows −
var emp = { name: "Zara", age: 10 };
You can write and read properties of an object using the dot notation as follows −
// Getting object properties emp.name // ==> Zara emp.age // ==> 10 // Setting object properties emp.name = "Daisy" // <== Daisy emp.age = 20 // <== 20
Arrays In jQuery
You can define arrays using the array literal as follows −
var x = []; var y = [1, 2, 3, 4, 5];
An array has a length
property that is useful for iteration −
var x = [1, 2, 3, 4, 5]; for (var i = 0; i < x.length; i++) { // Do something with x[i] }
Functions In jQuery
A function in JavaScript can be either named or anonymous. A named function can be defined using function
keyword as follows −
function demo(){ // do some stuff here }
An anonymous function can be defined in similar way as a normal function but it would not have any name. An anonymous function can be assigned to a variable or passed to a method as shown below.
var handler = function (){ // do some stuff here }
Arguments in functions In jQuery
JavaScript variable arguments is a kind of array
which has length
property. Following example explains it very well −
function func(x){ console.log(typeof x, arguments.length); } func(); //==> "undefined", 0 func(1); //==> "number", 1 func("1", "2", "3"); //==> "string", 3
Scopes In jQuery
JavaScript have two types of scopes:
var myVar = "global"; // ==> Declare a global variable function ( ) { var myVar = "local"; // ==> Declare a local variable document.write(myVar); // ==> local }
Note: Within the body of a function, a local variable takes precedence over a global variable with the same name.
Summary
To summarise, jQuery is a fast, lightweight, feature-rich client-side which uses JavaScript library. Hope you picked up a thing or two.
Cheers!