Skip to main content
added 130 characters in body
Source Link
Osama
  • 3k
  • 1
  • 16
  • 16

Override x value with in the function and return it like this codeCode below

function test(x){
   let obj={x:1,y:2}
   if(!x)x=obj;
   if(x.hasOwnProperty('x')){
   return x.x;
   }
   else{
    return "object does not have property x";
}
}
console.log(test(undefined));    //  {x:1,y:2}
console.log(test(false));    //  {x:1,y:2}
console.log(test(true));    //  true

Override x value with in the function and return it like this code

function test(x){
   let obj={x:1,y:2}
   if(!x)x=obj;
   return x;
}
console.log(test(undefined));    //  {x:1,y:2}
console.log(test(false));    //  {x:1,y:2}
console.log(test(true));    //  true

Override x value with in the function and return it like this Code below

function test(x){
   let obj={x:1,y:2}
   if(!x)x=obj;
   if(x.hasOwnProperty('x')){
   return x.x;
   }
   else{
    return "object does not have property x";
}
}
console.log(test(undefined));    //  {x:1,y:2}
console.log(test(false));    //  {x:1,y:2}
console.log(test(true));    //  true
Source Link
Osama
  • 3k
  • 1
  • 16
  • 16

Override x value with in the function and return it like this code

function test(x){
   let obj={x:1,y:2}
   if(!x)x=obj;
   return x;
}
console.log(test(undefined));    //  {x:1,y:2}
console.log(test(false));    //  {x:1,y:2}
console.log(test(true));    //  true