@@ -38,6 +38,11 @@ programming) styles.
38
38
- [ JavaScript Fundamentals- Part 2] ( #javascript-fundamentals--part-2 )
39
39
- [ Activating Strict Mode] ( #activating-strict-mode )
40
40
- [ Functions] ( #functions )
41
+ - [ Function Declarations & Expressions] ( #function-declarations--expressions )
42
+ - [ Arrow Functions] ( #arrow-functions )
43
+ - [ Functions Calling Other Functions] ( #functions-calling-other-functions )
44
+ - [ Introduction to Arrays] ( #introduction-to-arrays )
45
+ - [ Basic Arrays Operations Methods] ( #basic-arrays-operations-methods )
41
46
42
47
43
48
----
@@ -651,4 +656,151 @@ function Apple() {
651
656
}
652
657
653
658
Apple ();
654
- ```
659
+ ```
660
+
661
+
662
+ ## Function Declarations & Expressions
663
+
664
+ ``` jsx
665
+ // Fuction Declaration
666
+ function CalcAge1 (birthYear ) {
667
+ return 2037 - birthYear;
668
+ }
669
+ const age1 = calcAge1 (1991 );
670
+
671
+ // Function Expression
672
+ const calcAge2 = function (birthYear ) {
673
+ return 2037 - birthYear;
674
+ }
675
+ const age2 = calcAge2 (1991 );
676
+
677
+ console .log (age1, age2);
678
+
679
+ // 46 46
680
+ ```
681
+
682
+
683
+ ## Arrow Functions
684
+
685
+ ``` jsx
686
+ // Arrow Function
687
+ const calcAge3 = birthYear => 37 - birthYear;
688
+ const age3 = calcAge3 (1991 );
689
+ console .log (age3);
690
+
691
+ const yearsUntilRetirement = (birthYear , firstName ) => {
692
+ const age = 2037 - birthYear;
693
+ const retirement = 65 - age;
694
+
695
+ // return retirement;
696
+ return ` ${ firstName} restires in ${ retirement} years` ;
697
+ }
698
+ console .log (yearsUntilRetirement (1991 , ' John' ));
699
+ conosle .log (yearsUntilRetirement (1980 , ' Jacob' ));
700
+
701
+ // 46
702
+ // John retires in 19 years
703
+ // Jacob retires in 8 years
704
+ ```
705
+
706
+ ## Functions Calling Other Functions
707
+
708
+ ``` jsx
709
+ function cutFruitPieces (fruit ) {
710
+ return fruit * 4 ;
711
+ }
712
+
713
+ function fruitProcessor (apples , oranges ) {
714
+ const applePieces = cutFruitPieces (apples);
715
+ const orangePieces = cutFruitPieces (oranges);
716
+
717
+ const juice = ` Juice with ${ applePieces} apples and ${ orangePieces} oranges` ;
718
+ return juice;
719
+ }
720
+ console .log (fruitProcessor (2 , 3 ));
721
+
722
+ // Juice with 8 apples and 12 oranges
723
+ ```
724
+
725
+
726
+ ## Introduction to Arrays
727
+
728
+ ``` jsx
729
+ const fruits = [' apple' , ' orange' , ' banana' ];
730
+ console .log (fruits);
731
+
732
+ const years = [1991 , 1992 , 1993 ];
733
+ console .log (years [1 ]);
734
+
735
+ console .log (fruits .length );
736
+ console .log (fruits[fruits- length - 1 ]);
737
+
738
+ // ["apple", "orange", "banana"]
739
+ // 1992
740
+ // 3
741
+ // 3
742
+
743
+ ```
744
+
745
+
746
+ ## Basic Arrays Operations Methods
747
+
748
+ ``` jsx
749
+ console .log (newLength);
750
+
751
+ fruits .unshift (' grape' );
752
+ console .log (fruits);
753
+
754
+ // Remove Elements
755
+ fruits .pop (); // Last Element
756
+ const popped = fruits .pop ();
757
+ console .log (popped);
758
+ console .log (fruits);
759
+
760
+ fruits .shift (); // First Element
761
+ console .log (fruits);
762
+
763
+ console .log (fruits .indexOf (' orange' ));
764
+ console .log (fruits .indexOf (' watermelon' ));
765
+
766
+ fruits .push (23 );
767
+ console .log (fruits .includes (' orange' ));
768
+ console .log (fruits .includes (' watermelon' ));
769
+ console .log (fruits .includes (23 ));
770
+
771
+
772
+ if (fruits .includes (' orange' )) {
773
+ console .log (' You have a friend called orange' );
774
+ }
775
+
776
+
777
+ // Output
778
+
779
+ // [ 'apple', 'orange', 'banana', 'mango' ]
780
+ // 4
781
+
782
+ // 5
783
+ // [ 'grape', 'apple', 'orange', 'banana', 'mango' ]
784
+
785
+
786
+ // 'mango'
787
+
788
+ // 'banana'
789
+ // [ 'grape', 'apple', 'orange' ]
790
+
791
+ // 'grape'
792
+ // [ 'apple', 'orange' ]
793
+
794
+ // 1
795
+ // -1
796
+
797
+ // 3
798
+ // true
799
+ // false
800
+ // true
801
+
802
+
803
+ // 'You have a friend called orange'
804
+
805
+ //
806
+ ```
0 commit comments