Javascript Study Notes

JavaScript, often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, often incorporating third-party libraries. In this post, I will make some notes about my further study about JavaScript.


2023-02-04

  • Concatenate strings
    • var ourStr = “I come first! " + “I come last!”;
  • Get the length of strings
    • console.log(ourStr.length)
  • Strings are immutable
    • ourStr[0] = ‘C’; (This is wrong!)
  • Arrays
    • We can store any type of elements in our array.
    • arr.push(ele) can push elements into the array at back.
    • arr.pop() will remove the last element and return it.
    • arr.shift() will remove the first element and return it.
    • arr.unshift(ele) will add the element to the beginning of the array.
  • Functions
    • Format: function name( parameters ) {}
    • The outcome of a function that does not return anything will be undefined
  • Variable Scope:
    • If a variable is not modified by any keyword, then it will be set as a global variable.
    • Local variable will take precedence if it has the same name as the global variable.

2023-02-03

  • Escaping literal quotes in strings
    • var myStr = “I am a \“double quoted\” string”; (backslash)
    • var myStr = ‘I am a “double quoted” string’; (single quote)
    • var myStr = `I am a “double quoted” string`; (backtick)
  • Using backslash(\)
    • \n: newline
    • \r: carriage return (Carriage return means to return to the beginning of the current line without advancing downward)
    • \t: tab
    • \b: backspace
    • \f: form feed

2023-02-01

  • Data Types
    • undefined: a variable that has not been set to anything
    • null: nothing
    • boolean: true / false
    • string: any text
    • symbol: an immutable primitive value that is unique
    • number: a number
    • object: stores a lot of key value pairs
  • Declare a variable
    • var myName = “Jason”
      • “var” is going to be able to be used throughout the program
    • let ourName = “freeCodeCamp”
      • “let” will only be used within the scope that is declared
    • const pi = 3.14
      • “const” is a variable that should / can never be changed
    • If a value is declared but not assigned, any operation will not change that value. (Always prints null)
    • Variable names are case sensitive.

2023-01-17

  • A brower has two parts: rendering engine and JS engine.
    • Rendering engine is used to parse HTML and CSS code, e.g., blink of Chrome
    • JS engine is used to interpret and run JavaScript code, e.g., V8 of Chrome