pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/Hyuk/javascript/blob/master/javascript-basics/javascript-basics/functions.md

8dd150ce6c8e711.css" /> javascript/javascript-basics/javascript-basics/functions.md at master · Hyuk/javascript · GitHub
Skip to content

Latest commit

 

History

History
48 lines (41 loc) · 1.06 KB

File metadata and controls

48 lines (41 loc) · 1.06 KB

JavaScript Function Basic

Simple Function for Saying Hello World

function sayHello() {
    console.log("Hello World");
}
sayHello(); // Hello World

Simple Function for Adding two numbers

function addFunction(a, b) {
    console.log(a+b);
}
addFunction(3,5); // 8

...args Unkown number of parameters passing through a function

const sum = (function() {
  "use strict";
  return function sum(...args) {
    let sumNum = 0;
    for (let i = 0; i<args.length;i++){
      sumNum += args[i];
    }
    return sumNum; 
  };
})();
console.log(sum(1, 2, 3)); // 6

Array Queue Function

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line

function queue(arr,item) {
    arr.push(item);
    return arr.shift(); // return the shifted value in the array.
}

var testArr = [3,4,5,6,7];

console.log("Before: " + JSON.stringify(testArr)); // [3,4,5,6,7]
console.log(queue(testArr, 8)); // 3
console.log("After: " + JSON.stringify(testArr)); // [4,5,6,7,8]
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy