├── data-types.js ├── closure.js ├── scope.js ├── double-triple.js ├── true-false.js ├── primitive.js ├── summary.js ├── callback.js └── undefined-null.js /data-types.js: -------------------------------------------------------------------------------- 1 | // let a = 19; 2 | // console.log(typeof a); 3 | // let a = 'Jamal Uddin Shahen Shah'; 4 | let a = false; 5 | console.log(typeof a); -------------------------------------------------------------------------------- /closure.js: -------------------------------------------------------------------------------- 1 | function stopWatch() { 2 | let counter = 0; 3 | return function () { 4 | counter++; 5 | return counter; 6 | } 7 | } 8 | let clock1 = stopWatch(); 9 | console.log(clock1()); 10 | console.log(clock1()); -------------------------------------------------------------------------------- /scope.js: -------------------------------------------------------------------------------- 1 | const favNum = 27; 2 | 3 | function add(first, second) { 4 | // console.log(mood); // hoisting 5 | const result = first + second; 6 | 7 | if (result > 9) { 8 | let mood = 'happy'; 9 | mood = 'cranky'; 10 | } 11 | // console.log(mood); 12 | return result; 13 | } 14 | const sum = add(11, 35); 15 | // console.log(mood); 16 | 17 | for (let i = 0; i < 10; i++) { 18 | 19 | } 20 | // console.log(i); 21 | -------------------------------------------------------------------------------- /double-triple.js: -------------------------------------------------------------------------------- 1 | const first = '0'; 2 | const second = false; 3 | if (first == second) { 4 | console.log('condition is true'); 5 | } 6 | else { 7 | console.log('condition is false'); 8 | } 9 | 10 | //more comparison 11 | // const a = { name: 'ali' }; 12 | // const b = { name: 'ali' }; 13 | const a = []; 14 | const b = []; 15 | if (a === b) { 16 | console.log('both are same') 17 | } 18 | else { 19 | console.log('they are not same') 20 | } -------------------------------------------------------------------------------- /true-false.js: -------------------------------------------------------------------------------- 1 | /* 2 | Falsy: 3 | false 4 | 0 5 | empty string 6 | undefined 7 | null 8 | NaN 9 | ------------------- 10 | Truthy: 11 | true 12 | any number (positive or negative ) 13 | any string including single whitespace, '0', 'false' 14 | [] 15 | {} 16 | anything else that is not falsy will be truthy 17 | */ 18 | let x = {}; 19 | console.log('value of x', x) 20 | if (x) { 21 | console.log('variable is truthy'); 22 | } 23 | else { 24 | console.log('variable is Falsy'); 25 | } -------------------------------------------------------------------------------- /primitive.js: -------------------------------------------------------------------------------- 1 | /* 2 | Data types 3 | primitive data types 4 | 1. number 5 | 2. string 6 | 3. boolean 7 | 4. undefined 8 | 5. null 9 | 10 | 7. symbol 11 | 12 | non-primitive 13 | 6. object 14 | */ 15 | 16 | let a = 'hello'; 17 | let b = a; 18 | // console.log(a, b); 19 | a = 'gello'; 20 | // console.log(a, b); 21 | 22 | const x = { job: 'web developer' } 23 | const y = x; 24 | console.log(x, y); 25 | // x.job = 'front end developer'; 26 | y.job = 'front end developer'; 27 | console.log(x, y); -------------------------------------------------------------------------------- /summary.js: -------------------------------------------------------------------------------- 1 | const a = 'Alim uddin'; 2 | const b = 23; 3 | const c = true; 4 | // null 5 | // undefined 6 | 7 | // primitive 8 | // object 9 | 10 | const nums = [23, 12, 56, 34]; 11 | // console.log(typeof nums); 12 | // Array.isArray(nums) 13 | 14 | function triple(x, y, z) { 15 | x.age = 88888; 16 | // y = 2222; 17 | // z = 333; 18 | } 19 | // console.log(typeof triple); 20 | // console.log(triple.length); 21 | const num1 = 3; 22 | const num2 = 5; 23 | const num3 = 7; 24 | // triple(num1, num2, num3); 25 | const myObj = { name: 'kuddus', age: 17 }; 26 | triple(myObj); 27 | console.log(myObj); 28 | // console.log(num1, num2, num3); 29 | // console.log(typeof null); -------------------------------------------------------------------------------- /callback.js: -------------------------------------------------------------------------------- 1 | function welcomeMessage(name, greetHandler) { 2 | greetHandler(name); 3 | } 4 | // const names = ['Tom Hanks', 'Tom Brady', 'Tom Cruise'] 5 | // const myObj = { name: 'Tom Chinku', age: 11 }; 6 | function greetMorning(name) { 7 | console.log('Good morning', name); 8 | } 9 | function greetEvening(name) { 10 | console.log('Good Evening', name); 11 | } 12 | function greetAfternoon(name) { 13 | console.log('Good afternoon', name); 14 | } 15 | welcomeMessage('Tom Hanks', greetMorning); 16 | welcomeMessage('Sakib Hanks', greetAfternoon); 17 | welcomeMessage('Bappa Raj', greetEvening); 18 | 19 | function handleClick() { 20 | console.log('button is clicked'); 21 | } 22 | 23 | document.getElementById('my-btn').addEventListener('click', handleClick) 24 | 25 | document.getElementById('btn').addEventListener('click', function () { 26 | console.log('buttn is clicked'); 27 | }) -------------------------------------------------------------------------------- /undefined-null.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. variable value not assigned 3 | 2. function but didn't write return 4 | 3. just wrote return but didn't return anything 5 | 4. parameter that isn't passed 6 | 5. property that doesn't exist in an object 7 | 6. accessing array element out of range 8 | 7. accessing deleted array element 9 | 8. explicitly set value to undefined 10 | */ 11 | let first; 12 | // console.log(first); 13 | function second(x, y) { 14 | // document.getElementById('sum'); 15 | 16 | } 17 | const result = second(3, 91); 18 | // console.log(result); 19 | function add(a, b) { 20 | const sum = a + b; 21 | 22 | if (b < 10) { 23 | return; 24 | } 25 | const fun = a * b; 26 | return sum; 27 | } 28 | 29 | const fourth = add(2, 7); 30 | // console.log(fourth) 31 | function double(a, b) { 32 | const result = a * 2; 33 | // console.log(b); 34 | return result; 35 | } 36 | double(81); 37 | 38 | const fifth = { name: 'sogir', age: 15, location: 'bandarbon' }; 39 | // console.log(fifth.phone); 40 | 41 | const sixth = [54, 12, 41, 31]; 42 | // console.log(sixth[4]) 43 | delete sixth[2]; 44 | // console.log(sixth[2]); 45 | 46 | const seventh = undefined; 47 | // console.log(seventh); 48 | 49 | const myObj = { name: 'samad', profession: null } --------------------------------------------------------------------------------