Created
June 20, 2021 22:40
-
-
Save jusk02/ad9cf4ae9fdd3808cb957ecd53cd5675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Numbers | |
let myNumber = 123.1234; | |
console.log(myNumber); | |
console.log("toString: ", myNumber.toString()); | |
console.log("toFixed: ", myNumber.toFixed(0)); | |
console.log("toFixed: ", myNumber.toFixed(1)); | |
console.log("toFixed: ", myNumber.toFixed(4)); | |
console.log("valueOf myNumber: ", myNumber.valueOf()); | |
console.log("valueOf 123: ", (123).valueOf()); | |
console.log("valueOf 100 + 23", (100 + 23).valueOf()); | |
const myString = "145" | |
const myString2 = "Juan" | |
const myString3 = " 1 2" | |
const myString4 = " 12" | |
const myBoolean = true | |
console.log(`${myString} to Number:`, Number(myString)); | |
console.log(`${myString} to Float:`, parseFloat(myString)); | |
console.log(`${myString} to Integer:`, parseInt(myString)); | |
console.log(`${myString3} to Number:`, Number(myString3)); | |
console.log(`${myString3} to Float:`, parseFloat(myString3)); | |
console.log(`${myString3} to Integer:`, parseInt(myString3)); | |
console.log(`${myString4} to Number:`, Number(myString4)); | |
console.log(`${myString4} to Float:`, parseFloat(myString4)); | |
console.log(`${myString4} to Integer:`, parseInt(myString4)); | |
console.log(`${myBoolean} to Number:`, Number(myBoolean)); | |
console.log(`${myBoolean} to Float:`, parseFloat(myBoolean)); | |
console.log(`${myBoolean} to Integer:`, parseInt(myBoolean)); | |
console.log("the largest number in js is: ", Number.MAX_VALUE); | |
console.log("the smallest number in js is: ", Number.MIN_VALUE); | |
// STRINGS | |
const myText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
const myText2 = "hola mundo, hola devs"; | |
const myText3 = "hola mundo, _FIND-ME_ hola devs"; | |
const match = new RegExp(/\_(.*?)\_/g) | |
console.log(myText); | |
console.log(myText2); | |
console.log(myText3); | |
console.log("myText length is:", myText.length); | |
console.log("F in myText is position:", myText.search("F")); | |
console.log("Ñ in myText is position:", myText.search("Ñ")); | |
console.log("F in myText is position:", myText.indexOf("F")); | |
console.log("Ñ in myText is position:", myText.indexOf("Ñ")); | |
console.log("hola in myText2 is position:", myText2.indexOf("hola")); | |
console.log("F in myText2 is position:", myText2.lastIndexOf("hola")); | |
console.log("Ñ in myText2 is position:", myText2.lastIndexOf("tres")); | |
console.log("myText2 substring 2, 4 is:", myText2.substring(2,4)); | |
console.log("myText2 substring -10, -3 is:", myText2.substring(-10,-3)); | |
console.log("myText2 slice 2, 4 is:", myText2.slice(2,4)); | |
console.log("myText2 slice -10, -3 is:", myText2.slice(-10,-3)); | |
console.log("myText2 substr 2, 4 is:", myText2.substr(2,4)); | |
console.log("myText2 substr -10, -3 is:", myText2.substr(-8,3)); | |
console.log(myText2.replace("devs", "people")); | |
console.log(myText2.toUpperCase()); | |
console.log(myText.toLocaleLowerCase()); | |
// Objects | |
const myObject = { foo: 'bar', baz: 42 }; | |
console.log(myObject); | |
console.log("Entries", Object.entries(myObject)); | |
console.log("keys",Object.keys(myObject)); | |
console.log("values",Object.values(myObject)); | |
myObject.bar = "foo"; | |
console.log(myObject); | |
Object.freeze(myObject); | |
myObject.buz = "baz"; | |
console.log(myObject); | |
// Arrays | |
const fruits = ["Banana", "Orange", "Apple", "Mango"]; | |
const unsortedFruits = ["Banana", "Orange", "Rock",, "Apple", "Mango", "Rock"]; | |
console.log(fruits.length); | |
console.log(fruits); | |
console.log(fruits.push("Grape")); | |
console.log(fruits); | |
console.log(fruits.pop()); | |
console.log(fruits); | |
console.log(fruits.shift()); | |
console.log(fruits); | |
const bigFruits = fruits.map((fruit) => { | |
return "big ".concat(fruit); | |
}) | |
console.log(bigFruits); | |
console.log(unsortedFruits); | |
const realFruits = unsortedFruits.filter((fruit) => { | |
return fruit != "Rock" | |
}); | |
console.log(realFruits); | |
const numbers = [ 1, 4, 6, 3 , 10] | |
const firstEven = numbers.find((number) => { | |
return number % 2 === 0 | |
}); | |
console.log(firstEven); | |
const firstRock = unsortedFruits.indexOf("Rock") | |
console.log(firstRock); | |
const secondRock = unsortedFruits.indexOf("Rock", firstRock+1 ) | |
console.log(secondRock); | |
let isDirty = unsortedFruits.some((fruit) => { | |
return fruit === "Rock" | |
}) | |
console.log("unsortedFruits is dirty ", isDirty); | |
isDirty = fruits.some((fruit) => { | |
return fruit === "Rock" | |
}) | |
console.log("fruits is dirty ", isDirty); | |
let isClean = unsortedFruits.every((fruit) => { | |
return fruit != "Rock" | |
}) | |
console.log("unsortedFruits is clean ", isClean); | |
isClean = fruits.every((fruit) => { | |
return fruit != "Rock" | |
}) | |
console.log("fruits is clean ", isClean) | |
const smoothie = fruits.reduce((prep, fruit)=> { | |
return prep += `${fruit}-`; | |
},"") | |
console.log(smoothie); | |
const user = { | |
name: "juan", | |
age: 30, | |
hobbies: [ | |
"skate", | |
"play videogames", | |
"read" | |
] | |
} | |
const hobbiesString = user.hobbies.reduce((phrase, hobbie, index)=>{ | |
if (index+1 == user.hobbies.length) { | |
return phrase += ` and ${hobbie}.` | |
} | |
return phrase += `${hobbie},` | |
}, `${user.name} likes to `) | |
console.log(hobbiesString); | |
document.body.append(hobbiesString) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment