Skip to content

Instantly share code, notes, and snippets.

View amrelarabi's full-sized avatar

Amr Elarabi amrelarabi

View GitHub Profile
{
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
}
const filter = (...args) => args.filter(el => el === 1);
console.log(filter(1, 2, 3)); // [1]
let oldArray = [1, 2, 3];
let newArray = [...oldArray, 4, 5];
// [ 1, 2, 3 ]
console.log(oldArray);
[ 1, 2, 3, 4, 5 ]
console.log(newArray);
oldArray.pop();
[ 1, 2 ]
console.log(oldArray);
[ 1, 2, 3, 4, 5 ]
const oldArray = [1, 2, 3];
const newArray = [...oldArray, 4, 5];
// [1, 2, 3, 4, 5] المصفوفة الجديدة هى;
// يمكنك ايضًا إستخدامه مع objects
const oldObject = {
name: 'Kevin'
};
const newObject = {
...oldObject,
gender: 'Male'
class Person {
name = 'Jeo';
}
const person = new Person();
console.log(person.name);
class Person {
constructor () {
this.name = 'Jeo';
}
}
const person = new Person();
console.log(person.name); //طباعة الاسم
function Person(){
this.age = 0;
setInterval(() => {
this.age++; // this فى هذه الحالة تعود على person
}, 1000);
}
var p = new Person();
// فى حالة عدم وجود متغيرات
let sayHello = () => {
console.log("Hello");
}
sayHello();
// فى حالة عدم وجود متغير واحد يمكنك حذف ()
sayHello = myName => {
console.log("Hello " + myName);
}
sayHello("Jeo");
// نفترض دالة لحساب جمع رقمين
let sumTwoNumbers = ( x, y ) => {
return x + y;
}
console.log( sumTwoNumbers(2,3) );
//يمكنك ايضًا كتابتها بهذا الشكل فى حالة كانت الدالة سطر واحد
sumTwoNumbers = ( x, y ) => x + y;
console.log( sumTwoNumbers(2,3) );
const x = 10;
x = 20;
console.log(x);
// سيحدث خطأ : TypeError: Assignment to constant variable.