Javascript interview questions with answers

What are the advantages of using JSON rather than using xml

JSON is a lightweight format for storing and transferring data. When compared to xml, json files are of lesser size for the same amount of data as it doesnt need the extra tags as required by xml. Also, json is widely used in various languages.

Difference between Javascript Object and JSON format

There are 3 fundamental differences between Javascript Object and JSON format. They are

  1. 1. Keys should be enclosed in double quotes in JSON, but its not mandatory in javascript objects.
  2. 2. Javascript objects can have functions as value, whereas JSON may not contain functions.
  3. 3. The last value in a javascript object can have a trailing comma ‘,’, but in JSON its not the case (this is a structural difference only)

Difference between var and let

var can be redeclared within {}, but let cannot be redeclared.

1
2
3
4
5
var a = "my string";
var a = 5;// Does not throw error

let a = "my string";
let a = 5;// Uncaught SyntaxError: Identifier 'a' has already been declared

While var has function scope, let has block scope.

for(var i=10; i<20; i++) {
    //do something
}

console.log(i) // prints i as 20

for(let j=10; j<20; j++) {
    //do something
}
console.log(j) //j is not defined error

Related Content

Python interview questions with answers

Python interview questions with answers

This is a growing list hence, the article has been broken down into multiple parts

How to maintain multiple versions of django without using using virtual envs.

How to maintain multiple versions of django without using using virtual envs.

Most linux come installed with python 2.7. Some even come installed with both 2.7 and 3 as well.

Featured Posts

Types of Web Hosting

Types of Web Hosting