8000 update · sanketsangi/SimpleJavaScript@300fcad · GitHub
[go: up one dir, main page]

Skip to content

Commit 300fcad

Browse files
committed
update
1 parent ecfed8c commit 300fcad

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

README.md

+61-10
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ console.log(getFee(null));
643643

644644
# JavaScript Fundamentals- Part 2
645645

646+
----
647+
646648
## Activating Strict Mode
647649

648650
> `"use strict";` Defines that
@@ -657,6 +659,10 @@ JavaScript code should be executed in
657659

658660
## Functions
659661

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+
660666
```jsx
661667
function Apple() {
662668
console.log('iphone is Apple Inc. Product');
@@ -665,8 +671,9 @@ function Apple() {
665671
Apple();
666672
```
667673

668-
669674
## 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+
670677

671678
```jsx
672679
// Fuction Declaration
@@ -689,6 +696,9 @@ console.log(age1, age2);
689696

690697
## Arrow Functions
691698

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.
700+
701+
692702
```jsx
693703
// Arrow Function
694704
const calcAge3 = birthYear => 37 - birthYear;
@@ -712,17 +722,21 @@ conosle.log(yearsUntilRetirement(1980, 'Jacob'));
712722

713723
## Functions Calling Other Functions
714724

725+
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+
715729
```jsx
716730
function cutFruitPieces(fruit) {
717731
return fruit * 4;
718732
}
719733

720-
function fruitProcessor(apples, oranges) {
721-
const applePieces = cutFruitPieces(apples);
722-
const orangePieces = cutFruitPieces(oranges);
734+
function fruitProcessor(apples, oranges) {
735+
const applePieces = cutFruitPieces(apples);
736+
const orangePieces = cutFruitPieces(oranges);
723737

724-
const juice = `Juice with ${applePieces} apples and ${orangePieces} oranges`;
725-
return juice;
738+
const juice = `Juice with ${applePieces} apples and ${orangePieces} oranges`;
739+
return juice;
726740
}
727741
console.log(fruitProcessor(2, 3));
728742

@@ -732,6 +746,10 @@ console.log(fruitProcessor(2, 3));
732746

733747
## Introduction to Arrays
734748

749+
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.
750+
751+
752+
735753
```jsx
736754
const fruits = ['apple', 'orange', 'banana'];
737755
console.log(fruits);
@@ -752,6 +770,10 @@ console.log(fruits[fruits-length - 1]);
752770

753771
## Basic Arrays Operations Methods
754772

773+
[JavaScript Array Methods Tutorial – The Most Useful Methods Explained with Examples](#https://www.geeksforgeeks.org/javascript-basic-array-methods/)
774+
775+
776+
755777
```jsx
756778
console.log(newLength);
757779

@@ -815,6 +837,9 @@ if (fruits.includes('orange')) {
815837

816838
## Introduction to Objects
817839

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+
818843
```jsx
819844
const johnArray = [
820845
'John',
@@ -838,6 +863,11 @@ const john = [
838863

839864
## Dot vs Braket Notation
840865

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+
841871
```jsx
842872

843873
const john = {
@@ -853,8 +883,8 @@ console.log(john.lastName);
853883
console.log(john["lastName"]);
854884

855885
const namekey = '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]);
858888

859889
const intrestedIn = prompt('What do you want to know about John? Choose between firstName, lastName, age, job and favoriteFruit');
860890

@@ -898,6 +928,9 @@ console.log(john);
898928

899929
## Object Methods
900930

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 ().
932+
933+
901934
```jsx
902935

903936
const john = {
@@ -951,6 +984,12 @@ console.log(john.getSummary());
951984

952985
## Iteration: The For Loop
953986

987+
[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)
991+
992+
954993
```jsx
955994

956995
for (let rep = 1; rep <= 30; rep++) {
@@ -994,6 +1033,17 @@ for (let rep = 1; rep <= 30; rep++) {
9941033

9951034
## Looping Array, Breaking and Continuing
9961035

1036+
> [Looping Array](#https://www.w3docs.com/snippets/javascript/how-to-loop-through-an-array-in-javascript.html)
1037+
> Loops offer a quick and easy way to do something repeatedly.
1038+
1039+
> [Breaking](#https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break)
1040+
> The break statement terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.
1041+
1042+
> [Continuing](#https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue)
1043+
> 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+
9971047
```jsx
9981048

9991049
const john = [
@@ -1077,8 +1127,7 @@ for (let i = 0; i < john.length; i++) {
10771127

10781128
```
10791129

1080-
## Looping Backwards and Loops in Loops
1081-
1130+
## [Looping Backwards and Loops in Loops](#https://www.techiedelight.com/loop-through-array-backwards-javascript/)
10821131
```jsx
10831132

10841133
const john = [
@@ -1131,6 +1180,8 @@ for (let exercise = 1; exercise < 4; exercise++) {
11311180

11321181
## The While Loop
11331182

1183+
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.
1184+
11341185
```jsx
11351186

11361187
for (let rep = 1; rep <= 10; rep++) {

0 commit comments

Comments
 (0)
0