import React { Component } from 'react';
class Cobol extends Component{
state = {
numOfTimesHeSaidCobolIsGreat: 1
};
render(){
return (
<div>
<span>{this.cobolIsTheBestThingEver()}</span>
<button>BestProgLang</button
</div>
);
}
function cobolIsTheBestThingEver(){
const { numOfTimesHeSaidCobolIsGreat } = this.state;
return count === 0 ? "Pascal" : numOfTimesHeSaidCobolIsGreat;
}
}
export default Cobol;
function functionName(param1, param2, etc..){
//func logic goes here
}
- A function that is a parameter of another function
- The inner function is called as soon I invoke the outer function
const successfullyListeningTo = (nameOfSinger) => {
console.log(`You are successfully listening to ${nameOfSinger}!`);
}
const listenToSinger = (callbackfunc) => {
const singer = 'Sting'
callbackfunc(singer);
}
successfullyListeningTo(listenToSinger);
//You are successfully listening to Sting
coolfunc = function(){
return "This is a cool function!";
}
coolfunc = () => {
return "This is a cool Arrow Function!";
}
-
If the function has one statement I can omit:
- the return statement
- the curly braces
coolfunc = () => "This is a cool Arrow Function!";
coolfunc = (myval) => {
return "Hi there " + myval;
}
- IF the Arrow function has only one parameter I can omit:
- the parentheses
- the return statement
coolfunc = myval => "Hi there " + myval;
- alert() function: outputs data in an alert box in a window
- confirm() function: opens a yes/no option dialog box and returns a boolean value depending on the user click
- console.log() function: writes stuff to the browser console
- document.write() function: writes stuff directly to the HTML doc
- prompt(): creates a dialogue for user input
- concat(): join several arrs into one
- indexOf(): Search the array for the specified element if found return its position else return -1
- join(): combines the elements into a single string and returns that string
- lastIndexOf(): outputs the last position at which a given element exists in the array
- pop(): removes the last element within the array
- push(): add a new element to the end of the array
- replace(): Replace a specified value with another value in the String
- reverse(): reverse the order of the items in the array
- search(): search the string for the specified value and position of the match
- shift(): remove the first item in the array
- slice(): pulls a copy of a portion of the array into a new arr
- sort(): sort the items in the array alphabetically
- splice(): adds elements in a specific way and position
- toString(): converts the element to Strings aka the renowed Java must know method
- unshift(): adds a new element to the array at the beginning
- var: cannot be reassigned
- const: cannot be reassigned and cannot be used before they are declared
- let: can be reassigned but not redeclared
- ... : Spread operator expands an array into its elements
- filter(): Filter method creates a new array and fills it up with the elements that meet a certain condition
- map(): similar to filter but is used to modify elements instead
- reduce(): transform the array into something else i.e. reduce the array into one value
- includes(): check if a specified string exists within the array
const myArr = [2,4,6,"b","c"];
let myNum = 6;
console.log(myArr.toString()); //Prints "2,4,6,b,c"
console.log(myNum.toString()); //Print "6"
const myArr = ["Grand Theft Auto","True Crime","PUBG","COD","Saints Row"];
let myNum = 6;
console.log(myArr.join()); //Prints Grand Theft Auto, True Crime, PUBG,COD, Saints Row
console.log(myArr.join(" ")); //Prints Grand Theft Auto True Crime PUBG COD Saints Row
console.log(myArr.join("-")); //Prints Grand Theft Auto-True Crime-PUBG-COD-Saints Row