Showing posts with label Difference between. Show all posts
Showing posts with label Difference between. Show all posts

Tuesday 24 March 2015

What is difference between event.preventDefault() and return false in Javascript?

What is difference between event.preventDefault() and  return false in Javascript?


e.preventDefault() will prevent the default event from occuring.
Means If this method is called, the default action of the event will not be triggered.

This method does not accept any arguments.
Example:
jQuery(document).ready(function(){
    $('a.link').click(function (e) {
        e.preventDefault();
    });
});



e.stopPropagation() will prevent the event from bubbling.
Means If this method is called, It Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

This method also does not accept any arguments.
Example:
jQuery(document).ready(function(){
    $('a.link').click(function (e) {
        e.stopPropagation();
    });
});



return false: Will do above both that is preventDefault & stopPropagation.
Example:
jQuery(document).ready(function(){
    $('a.link').click(function (e) {
        return false;
    });
});




What is the difference between call and apply in javascript?


What is the difference between call and apply in javascript?


In Javascript, call() and apply() are predefined methods. Both methods can be used to invoke a function & must have the owner object as first parameter. See More detail below:


apply lets you invoke the function with arguments as an array.
View Example:
            function myFunction1(a, b) {
                return a + b;
            }
            var myobj1 = new Object();
            var result1 = myFunction1.call(myobj1, 5, 6);
            console.log('Result with call function: ' + result1);



call requires the parameters be listed explicitly one by one.
View Exmple:
            function myFunction2(a, b) {
                return a + b;
            }
            myArray = [5, 6];
            var myobj2 = new Object();
             var result2 = myFunction2.apply(myobj2, myArray);   
             console.log('Result with Apply function: ' + result2);





Sunday 22 March 2015

Difference between inner join and outer join in MySQL

Difference between inner join and outer join in MySQL


Joins are used to get the records from two OR more tables. Following are different type of joins  used in mysql.
  • Left Join
  • Right Join
  • Inner Join
  • Self Join
  • Outer Join


Following are difference between Inner Join & Outer Join.

Inner Join: It is used to get the common records from two table or more tables.

MySQL Inner Join Example:
SELECT * FROM `geo_cities` as gc INNER JOIN meta_data AS md on md.city_id=gc.id;


Outer Join: It is used to get the all records from two tables or more tables.
MySQL Outer Join Example:
MySQL does not provide the FULL JOIN.
You need to UNION the result of Right Join and Left Join from both tables.
SELECT * FROM `geo_cities` as gc LEFT JOIN meta_data AS md on md.city_id=gc.id
UNION
SELECT * FROM `geo_cities` as gc RIGHT JOIN meta_data AS md on md.city_id=gc.id




Wednesday 11 March 2015

Difference between theme and template in website


Difference between theme and template in website

Template:
A website template is a set of HTML webpages (It have Own JS/CSS/Images) that gives a beautiful look of website. An Website can be more than one template and each template will have different design.

For Example:
 Desktop version: We show full fledge content of website with lot of other options like View Related post, What other are viewing, Big images and Big Font size etc.
 Mobile version:  We show full fledge content of website with limited option like View Related post, and What other are viewing, show small images and small fount etc


Theme:
A Theme is a part of Template. One template can have one or more themes. Each theme can have its own JS/CSS/Images. Two different themes of same template will have same design but their color combinations and images may be different.




Tuesday 10 March 2015

Difference between in_array and array_key_exists in php with example

Difference between in_array and array_key_exists in php with example

in_array: Checks if a value exists in an array OR not.
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] );

Parameters
needle: The searched value.
haystack: The array.
strict: If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.

Return: Returns TRUE if needle is found in the array, FALSE otherwise.

Example:
$array = array("Web", "Technology", "Experts", "Notes");
if (in_array("Technology", $array)) {
    echo "Record Found in value";
}



array_key_exists: Checks if the given key/index exists in the array.
bool array_key_exists ( mixed $key , array $array );
Parameters key: Value to check.
array: An array with keys to check.

Return: Returns TRUE on success or FALSE on failure.

Example:
$searchArray = array('Web' => 1, 'Technology' => 4);
if (array_key_exists('Web', $searchArray)) {
    echo "Record Found in key";
}