An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
10 javascript basics interns should know before the job
tldr; learn typescript and es6 |
I have spent a lot of time doing crash courses on JS and TS basics instead of using the time to work on the actual code. Here is what I would recommend anyone know before getting an internship or job for js related work.
1. Typescript . Yes, learn typescript before getting any javascript job. It's a steep learning curve and you will struggle so much trying to understand it if you don't have the basics. See this course on egghead.io or this longer course on udemy by our friend Max. And try and remember: typescript doesn't run at runtime!
2. Arrow functions
const coolFunction { return returnValue } // DON'T DO THISconst coolFunction = () => returnValue // DO THIS
3. Template literals
let fruit = "oranges"const stringValue = `I love ${fruit}` // I love orangesconst fancier = `I love ${favFruit()?.answers?.[0]?.value || "fruit"}` // See below for what this means
4. Property shorthand
let a = "something"let b = "something else"const myObject = { a, b} // same as { a: a, b: b}
5. Destructuring assignment
let { name, email } = contact // same as name = contact.name..// or go deeper - careful as contact needs // to exist and wont be set as variable, only address willlet { contact : { address}} = person // address = person.contact.address
6. Spread operators
Merge arrays and objects easily
let stuff = [ "bye", false, 3 ]var mergedStuff = [ 1, 2, ...stuff ] // [ 1, 2, "bye", false, 3 ]
7. Optional chaining
Only use if ... then
when you need it. Use optional chaining instead.
// this is a getter, ie computed type variable// learn that too!get pronouns() { // safely returns undefined rather than // blowing up with "can't get property x of undefined" return person?.details?.pronouns }// How to use it with functions and arrays:let email = getSomething()?.email// You could also do this:let { email } = getSomething();let deepThing = myFunction()?.someArrayProp?.[0]?.detail
8. Common JS methods
Don't shy away from the MDN webdocs, see e.g. .some
let transformedArray = myArray.map(...)let anArray = myArray.filter(...) // filters outlet aBoolean = myArray.some(...) // .includes, .many, .everylet anItem = myArray.find(...) // returns first item
9. Lodash
Mainly, _.get
, _.set
, _.uniq
, _.omit
, _.difference
10. JS Doc
/** * Documenting stuff matters * @param thing - An important input * @returns otherthing - Clearly expected result */const gardenFunction = (thing: string) => otherthing
Combining these learnings you need to be able to write and understand:
type Person = { name: string; contact: { address: string; email?: string; };};const listOfPeople = [];/** * Find a person's email by name (case insensitive) * @param name - name the name. you are looking for * @returns {Person | null} - the person's email or null if not found */const findPersonEmailByName = (name): Person | null => listOfPeople.find((p) => p.name.toLowerCase() == name.toLowerCase())?.contact?.email || null null;
Original Link: https://dev.to/omills/10-things-i-wish-dev-interns-knew-before-the-job-eo1
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To