JavaScript Questions
#### What will be the output of the following code?
```javascript
console.log(1 + "2" + "2");
console.log(1 + +"2" + "2");
console.log(1 + -"1" + "2");
console.log(+"1" + "1" + "2");
```
1. [ ] 122, 32, 02, 112
2. [ ] 122, 12, 12, 112
3. [x] 122, 32, 02, 112
4. [ ] 122, 32, 12, 112
#### What will be the output of the following code?
```javascript
function foo() {
return {
bar: "hello"
};
}
console.log(foo());
```
1. [ ] undefined
2. [x] { bar: "hello" }
3. [ ] { bar: "hello" } and { bar: "hello" }
4. [ ] Error
#### What will be the output of the following code?
```javascript
var a = [1, 2, 3];
var b = [1, 2, 3];
var c = "1,2,3";
console.log(a == c);
console.log(a === c);
console.log(a == b);
console.log(a === b);
```
1. [ ] true, true, true, true
2. [ ] true, true, false, false
3. [x] true, false, false, false
4. [ ] false, false, false, false
#### What will be the output of the following code?
```javascript
var x = 21;
var girl = function() {
console.log(x);
var x = 20;
};
girl();
```
1. [ ] 21
2. [ ] 20
3. [x] undefined
4. [ ] Error
#### What will be the output of the following code?
```javascript
var x = 0;
function foo() {
x++;
this.x = x;
return foo;
}
var bar = new new foo;
console.log(bar.x);
```
1. [ ] 1
2. [x] undefined
3. [ ] 0
4. [ ] Error
#### What will be the output of the following code?
```javascript
console.log(0.1 + 0.2 === 0.3);
```
1. [ ] true
2. [x] false
3. [ ] Depends on the browser
4. [ ] Error
#### What will be the output of the following code?
```javascript
console.log(1 < 2 < 3);
console.log(3 > 2 > 1);
```
1. [ ] true, true
2. [ ] true, false
3. [x] true, false
4. [ ] false, true
#### What will be the output of the following code?
```javascript
var b = 1;
function outer() {
var b = 2
function inner() {
b++;
var b = 3;
console.log(b);
}
inner();
}
outer();
```
1. [ ] 2
2. [x] 3
3. [ ] 3 and undefined
4. [ ] Error
#### What will be the output of the following code?
```javascript
function func(a, b, c) {
console.log(arguments.length);
}
func(1, 2);
```
1. [ ] 1
2. [x] 2
3. [ ] 4
4. [ ] 3
#### What will be the output of the following code?
```javascript
console.log(typeof null);
```
1. [x] object
2. [ ] null
3. [ ] array
4. [ ] undefined
#### What will be the output of the following code?
```javascript
var x = 10;
function foo() {
console.log(x);
var x = 5;
}
foo();
```
1. [ ] 10
2. [ ] 5
3. [x] undefined
4. [ ] Error
#### What will be the output of the following code?
```javascript
var arr = [];
arr[0] = 'a';
arr[1] = 'b';
arr.foo = 'c';
console.log(arr.length);
```
1. [ ] 0
2. [ ] 4
3. [x] 2
4. [ ] 3
#### What will be the output of the following code?
```javascript
function func(a, b, c) {
console.log(arguments.length);
}
func(1, 2);
```
1. [ ] 1
2. [ ] 4
3. [x] 2
4. [ ] 3
#### What will be the output of the following code?
```javascript
var obj = { a: 1 };
console.log(obj + 1);
```
1. [ ] 1
2. [ ] { a: 1 }1
3. [x] [object Object]1
4. [ ] Error
#### What will be the output of the following code?
```javascript
console.log(1 + "2" + "2");
console.log(1 + +"2" + "2");
console.log(1 + -"1" + "2");
console.log(+"1" + "1" + "2");
```
1. [x] 122, 32, 02, 112
2. [ ] 122, 12, 12, 112
3. [ ] 122, 42, 02, 112
4. [ ] 122, 32, 12, 112
#### What will be the output of the following code?
```javascript
console.log(Number("1") - 1 == 0);
console.log("1" + 1 == 11);
console.log("11" - 1 == 1);
console.log([] + null + 1 == "null1");
console.log([] + 1 == "1");
console.log({} + [] + {} + [1] == "0[object Object]1");
```
1. [x] true, false, false, true, true, true
2. [ ] true, true, true, true, true, true
3. [ ] true, true, true, false, false, true
4. [ ] true, true, true, true, false, true
#### What will be the output of the following code?
```javascript
var x = 0;
function foo() {
x++;
this.x = x;
return foo;
}
var bar = new new foo;
console.log(bar.x);
```
1. [x] 1
2. [ ] undefined
3. [ ] 0
4. [ ] Error
#### What will be the output of the following code?
```javascript
var x = 0;
function foo() {
console.log(x);
var x = 5;
}
foo();
```
1. [x] undefined
2. [ ] 5
3. [ ] 0
4. [ ] Error
#### What will be the output of the following code?
```javascript
console.log(1 + "2" + "2");
console.log(1 + +"2" + "2");
console.log(1 + -"1" + "2");
console.log(+"1" + "1" + "2");
```
1. [ ] 122, 42, 02, 112
2. [ ] 122, 12, 12, 112
3. [x] 122, 32, 02, 112
4. [ ] 122, 32, 12, 112
#### What will be the output of the following code?
```javascript
var x = 10;
function foo() {
console.log(x);
var x = 5;
}
foo();
```
1. [ ] Error
2. [ ] 5
3. [x] undefined
4. [ ] 10