Javascript concepts

kartik goyal
Sep 20, 2023
  1. How to access value when key name comes from a variable (V) in js object(O)?
    Using square bracket ([]). For example: O[V]
  2. Array(count).fill() — create a array of size count and fill it with undefined number can be used when for .map() or using other array properties.
  3. Array sorting — [].sort(() => {return boolean}) — conditional sorting js
  4. const frequencyMap = new Map(); Eg: Map(4) { ‘a’ => 7, ‘b’ => 5, ‘e’ => 5, ‘c’ => 2 }
    — Properties ->
    — has -> to check if element exist
    — set -> to add the element
    — enteries -> to search
  5. ?? — nullish coalescing operator
    — Returns right handside value (defaultVal) if left handside value (someVal) is null or undefined
    — someVal ?? defaultVal
  6. Javascript replace function
    single replace — str.replace(/string/, ‘replacement’)
    global replace — str.replace(/string/g, ‘replacement’) (g — global)

--

--