What is difference between declaring variable using var and without var?

```
a=2;
b=2;
if(a==b)//returning false
if(a===b)//returning false

var a=2;
var b=2;
if(a==b)//returning true
if(a===b)//returning true

```

Why?