ElpeAJ / JS_homework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Summarization of Articles


JavaScript Array length

Example:

The length property returns the length (size) of an array:
const list = ["Banana", 78, "Apple", 56];
let size = list.length; //prints 4 to the screen

Why Functions?

With functions you can reuse code
You can write code that can be used many times.
You can use the same code with different arguments, to produce different results.
A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).

Example:

//Function to compute the product of 2 numbers
function myFunction(p1, p2) {
return p1 * p2;
}
console.log(myFunction(2, 4));

Defining functions

Regular function: can return anything;
always runs to completion after invocation

Generator function: returns a Generator object;
can be paused and resumed with the yield operator

Async function: returns a Promise; can be paused
and resumed with the await operator

Async generator function: returns an AsyncGenerator object;
both the await and yield operators can be used

In JavaScript, there are three main types of control flow statements:

if/else statements
switch statements
loops.

Function Declaration

To create a function we can use a function declaration.
It looks like this:

Example:

function showMessage() {
alert( 'Hello everyone!' );
}

showMessage();
showMessage();

About


Languages

Language:JavaScript 100.0%