Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created June 1, 2021 16:09
Show Gist options
  • Save MohammedALREAI/f4ef84b02174dbab9d45e7b7983d8d9a to your computer and use it in GitHub Desktop.
Save MohammedALREAI/f4ef84b02174dbab9d45e7b7983d8d9a to your computer and use it in GitHub Desktop.
JavaScript assignment 2‏
// call by value when you are used any the prmitive type like
// number ,string ,boolean ,undefined ,null like
// are always assigned/passed by
// value-copy: null, undefined, string, number, boolean, and ES6’s symbol.
// - First: Pass by value example
// some hint
// The original variable is not modified on changes in other variables.
let x=10;
// which it is the value x is assign to 10
let a = 2;
let b = a; // `b` is always a copy of the value in `a`
b++;
a; // 2
b; // 3
// refrance
// any thing like array and object and function it just reference value
// like
let numArr:number[]=[1,2,3]
let copyarr = numArr; // `copyarr` is a reference to the shared `[1,2,3]` value
// when you create function
function addOne(x:number){
return ++x
}
// when you what to call it or used it like this
let tow=addOne(1)
// which tow refrance to the location that relized to some poin in to the addOne function
let newObj = { greeting : 'call' };
let someFature;
someFature = newObj;
// Mutating the value of c
newObj.greeting = 'call by refrance';
console.log(newObj) //{greeting:"'call by refrance';"}
console.log(someFature);//{greeting:"'call by refrance';"}
// call by value and refeance
function multiplication(arr:number[]){
let newCopy=[...arr]
return newCopy.map(x=>x*2)
}
// call function
let squire= multiplication(numArr)
// Make a function to get data from this API: "https://jsonplaceholder.typicode.com/todos/1", and don't forget to use error handling.
async function laodData():Promise<any>{
try{
const res=await fetch("https://jsonplaceholder.typicode.com/todos/1")
let todosJson= await res.json()
return console.log(todosJson)
}
catch(e){
throw new Error(`ther are some error happend ${e}`)
}
}
console.log(laodData());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment