Interview questions

Exercise on Interview questions

by sendil J

JavaScript

var a = {
  a: 0,
  b: function send() {} 
}

function local() {
  var b = a;
  b.a = 10;
  console.log(a); // {a:10, b:function}
}
local();
console.log(a); //{a:10, b:function}
console.log(json.stringify(a)); // error will not stringify


/*var a = 0;
function test() {
  console.log('1', a); //undefined
  var a = 100;
  console.log('2', a); // 100
}
test();
console.log('3', a); //0
*/
/*
var MyApp = {a:0}; // Globally scoped object

function foo() {
  console.log(MyApp); //{a: 0}
  MyApp.color = 'green';
}
foo();*/
/*
function one() {
  var a = 0;
  two(a);
}

function two(val) {
  console.log(val); // 0
}
one();
*/
/*
function one(){
   function two(){
      a=10;
   }
  
  two();
}

one();
console.log(a); //10

*/
/*
function one() {
  var a;

  this.two = function() {
    a = 10;
    return a;
  }

  return a;
}
var three = new one();
console.log(three.two());
*/