Categories
JavaScript jQuery Web

JavaScript Basics: Difference between == & === (with examples)

JavaScript has two sets of equality operators: === and ==. They mostly work exactly the same ie, if the operands are of the same type and have the same value, then === produces true & so does ==. But if the operands are of different types, then === produces false & == says true. The simplest reason is that == is also a type converter.

Here are some examples of === & == in action:

true == 1 // true
true === 1 // false, because they are of a different type
1 == "1" // true, automatic type conversion for value only
1 === "1" // false, because they are of a different type
null == undefined // true
null === undefined // false

== is also notoriously inconsistent. See the below examples:

'' == '0' // false
0 == '' // true
0 == '0' // true

false == 'false' // false
false == '0' // true

false == undefined // false
false == null // false
null == undefined // true

' \t\r\n ' == 0 // true

Best practice is to avoid == and use === consistently in your code.

Categories
JavaScript jQuery Solutions Web

JavaScript Loop Through Select Options – Example

Sometimes we need to iterate through all the options of a DropDown list (and perform operations based on each one). Here is how to do it(for a dropdown with the id “dropdownlist”)

JavaScript:

var x= document.getElementById("dropdownlist");
for(i=0; i<x.options.length;i++){
console.log(x.options[i].value);
//Add operations here
}

JQuery:

$("#dropdownlist > option").each(function() {
console.log(this.text + ' ' + this.value);
//Add operations here
});

Categories
Android Nexus 5

Turn Off Keyboard Vibration in Android Lollipop

Google Keyboard is the default keyboard in Android 5, Lollipop. By default, its configured to enable vibration on key press. If you are someone who dislikes this feature, here is a simple way to turn off keyboard vibration in it:

Steps to Disable or Turn Off Keyboard Vibration:

  • Go to Home -> Settings -> Language & input
  • Locate “Google Keyboard” (under Keyboard & input methods) and tap it
  • Tap on Preferences
  • Turn off the “Vibrate on keypress” option

UPDATE: For Android 6 (Marsh Mallow) use these steps

Categories
Android Apps FaceBook Solutions Web

How to Disable Facebook Links from opening in the Facebook App Browser

Facebook logo Español: Logotipo de Facebook Fr...Facebook recently update added a new feature to its mobile app. The feature loads all links clicked on Facebook to open in the in-app browser as opposed to a browser installed on the phone. While this is faster, it seriously limits what you can do with the open page (for eg. sharing is limited). But fortunately this feature can be disabled.

To disable it, do the following:

  1. In the Facebook app, goto Menu > App Settings
  2. In General Settings, you will find the “Always open links with external browser” option. Tap it to Enable it.
  3. Now your facebook app should behave just the way it did before the update.

Screenshots:
_20141117_204056 _20141117_204038

Categories
Internet Explorer Solutions Web

How to force Internet Explorer to view a page in a specific version mode.

Internet Explorer 7
Internet Explorer 7 (Photo credit: Wikipedia)

Meta tags can be used to force Internet Explorer(IE) browser to use a specific standards mode. The X-UA-Compatible meta tag tells IE what view mode to use to render the current page.

Here is how to emulate different browser modes using meta tags:

Emulate IE 7:

<meta http-equiv="X-UA-Compatible" content="IE=7">

Emulate IE 8:

<meta http-equiv="X-UA-Compatible" content="IE=8">

Emulate IE 9:

<meta http-equiv="X-UA-Compatible" content="IE=9">

If the end client visits the page on a browser that is older than the specifed view mode (eg. User has IE 8 but view mode forces IE 9), the browser will ignore the meta tag and render the page the best way it can.