|
| 1 | +//JavaScript function with out html |
| 2 | +//Code Drive Invocation |
| 3 | +function myFunction(fullName, age, dateOfBirth = 1991) { |
| 4 | + console.log('Hello ' + fullName + "I'm " + age + " years old. " + ' My date of birth ' + dateOfBirth + '.'); |
| 5 | +} |
| 6 | + |
| 7 | +myFunction('Sahin. ',20, 2000); |
| 8 | +myFunction('Enam. ',17, ); |
| 9 | + |
| 10 | +//function with html |
| 11 | +//Even Driven Invocation |
| 12 | +function isSubscribed() { |
| 13 | + console.log("Subscribed"); |
| 14 | +} |
| 15 | +document.getElementById('btn').addEventListener('click', isSubscribed); |
| 16 | + |
| 17 | + |
| 18 | +//Automatic (Self-Invoked) Invocation |
| 19 | +(function () { |
| 20 | + console.log('I am Self-Invoked function')(); |
| 21 | +}) |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +//Use function in variable |
| 26 | +let maths = function(x, y) { |
| 27 | + return x * y; |
| 28 | +}; |
| 29 | +console.log(maths (3,4)); |
| 30 | +console.log(maths (50,8)); |
| 31 | + |
| 32 | + |
| 33 | +//Arry |
| 34 | +let number = [2,3,4,5,8,90,100]; |
| 35 | +let sqNumbers = number.map(function (number) { |
| 36 | + return number * number; |
| 37 | +}) |
| 38 | +console.log(sqNumbers); |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +let add = function (x,y) { |
| 44 | + return x + y; |
| 45 | +} |
| 46 | +console.log(add(5,6)); |
| 47 | + |
| 48 | +//Arrow function |
| 49 | +let add1 = (x,y) => x + y; |
| 50 | +console.log(add(6,90)); |
| 51 | + |
| 52 | +//Next state function |
| 53 | +function greet(firstName) { |
| 54 | + function sayHello() { |
| 55 | + alert('Hi ' + firstName); |
| 56 | + } |
| 57 | + return sayHello(); |
| 58 | +} |
| 59 | +greet('Sahin Enam'); |
| 60 | + |
| 61 | + |
0 commit comments