You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-10
Original file line number
Diff line number
Diff line change
@@ -643,6 +643,8 @@ console.log(getFee(null));
643
643
644
644
# JavaScript Fundamentals- Part 2
645
645
646
+
----
647
+
646
648
## Activating Strict Mode
647
649
648
650
> `"use strict";` Defines that
@@ -657,6 +659,10 @@ JavaScript code should be executed in
657
659
658
660
## Functions
659
661
662
+
A [JavaScript function](#https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions) is a block of code designed to perform a particular task.
663
+
A JavaScript function is executed when "something" invokes it (calls it).
664
+
665
+
660
666
```jsx
661
667
functionApple() {
662
668
console.log('iphone is Apple Inc. Product');
@@ -665,8 +671,9 @@ function Apple() {
665
671
Apple();
666
672
```
667
673
668
-
669
674
## Function Declarations & Expressions
675
+
The [function declaration](#https://medium.com/@mandeep1012/function-declarations-vs-function-expressions-b43646042052) (function statement) defines a function with the specified parameters.
676
+
670
677
671
678
```jsx
672
679
// Fuction Declaration
@@ -689,6 +696,9 @@ console.log(age1, age2);
689
696
690
697
## Arrow Functions
691
698
699
+
An [arrow function](#https://www.codecademy.com/resources/docs/javascript/arrow-functions) expression has a shorter syntax when compared to a function expression and does not have its own this, arguments, super or new.target. These function expressions are best applied to functions other than methods, and they cannot be used as constructors.
To [call a function inside another function](#https://bobbyhadz.com/blog/javascript-call-function-inside-function), define the inner function inside the outer function and invoke it. When using the function keyword, the function gets hoisted to the top of the scope and can access any of the available variables in the scope.
726
+
727
+
728
+
715
729
```jsx
716
730
functioncutFruitPieces(fruit) {
717
731
return fruit *4;
718
732
}
719
733
720
-
functionfruitProcessor(apples, oranges) {
721
-
constapplePieces=cutFruitPieces(apples);
722
-
constorangePieces=cutFruitPieces(oranges);
734
+
functionfruitProcessor(apples, oranges) {
735
+
constapplePieces=cutFruitPieces(apples);
736
+
constorangePieces=cutFruitPieces(oranges);
723
737
724
-
constjuice=`Juice with ${applePieces} apples and ${orangePieces} oranges`;
725
-
return juice;
738
+
constjuice=`Juice with ${applePieces} apples and ${orangePieces} oranges`;
An [array](#https://attacomsian.com/blog/javascript-arrays) is a list-like object in JavaScript that can be used to store multiple values in a single variable. It is an ordered-collection of values where each value is called an element that has a pre-defined numeric position in the array, referred to as its index.
[JavaScript Array Methods Tutorial – The Most Useful Methods Explained with Examples](#https://www.geeksforgeeks.org/javascript-basic-array-methods/)
774
+
775
+
776
+
755
777
```jsx
756
778
console.log(newLength);
757
779
@@ -815,6 +837,9 @@ if (fruits.includes('orange')) {
815
837
816
838
## Introduction to Objects
817
839
840
+
In JavaScript, most things are [objects](#https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects), from core JavaScript features like arrays to the browser APIs built on top of JavaScript. You can even create your own objects to encapsulate related functions and variables into efficient packages and act as handy data containers. The object-based nature of JavaScript is important to understand if you want to go further with your knowledge of the language, therefore we've provided this module to help you. Here we teach object theory and syntax in detail, then look at how to create your own objects.
841
+
842
+
818
843
```jsx
819
844
constjohnArray= [
820
845
'John',
@@ -838,6 +863,11 @@ const john = [
838
863
839
864
## Dot vs Braket Notation
840
865
866
+
Property accessors provide access to an object's properties by using the [dot notation or the bracket notation](#https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors).
867
+
868
+
869
+
870
+
841
871
```jsx
842
872
843
873
constjohn= {
@@ -853,8 +883,8 @@ console.log(john.lastName);
853
883
console.log(john["lastName"]);
854
884
855
885
constnamekey='Name';
856
-
console.log(jonas['first'+ nameKey]);
857
-
console.log(jonas['last'+ nameKey]);
886
+
console.log(john['first'+ nameKey]);
887
+
console.log(john['last'+ nameKey]);
858
888
859
889
constintrestedIn=prompt('What do you want to know about John? Choose between firstName, lastName, age, job and favoriteFruit');
860
890
@@ -898,6 +928,9 @@ console.log(john);
898
928
899
929
## Object Methods
900
930
931
+
[Object Methods](#https://javascript.
F438
info/object-methods) in JavaScript can be accessed by using functions. Functions in JavaScript are stored as property values. The objects can also be called without using bracket ().
[Loops](#https://www.freecodecamp.org/news/exploring-javascript-for-in-loops-bdfc226d8515/) allow programs to perform repetitive tasks, such as iterating through an array, while adhering to the DRY principle (Don’t Repeat Yourself). They come in handy when you want to execute a function a number of times, using different sets of inputs each time.
988
+
989
+
990
+
> [Iterate with JavaScript For Loops](#https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops)
> The break statement terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.
> The continue statement terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.
1044
+
1045
+
1046
+
997
1047
```jsx
998
1048
999
1049
constjohn= [
@@ -1077,8 +1127,7 @@ for (let i = 0; i < john.length; i++) {
1077
1127
1078
1128
```
1079
1129
1080
-
## Looping Backwards and Loops in Loops
1081
-
1130
+
## [Looping Backwards and Loops in Loops](#https://www.techiedelight.com/loop-through-array-backwards-javascript/)
The [while](#https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while) statement creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.
0 commit comments