D2: Javascript Fundamentals

devfish·2022년 12월 16일
0

Javascript

목록 보기
4/30

*learned basic velog markup
new q: 1) how to write french accents in a string, 2) what exactly is node.js?

more:

// Nan: Not A Number 
// `return` can be followed by any operation
// template literal: you can change lines! 
// == -> useless!
// falsey => treated as false 
// null - when you want to deliberately specify that it's empty. vs. undefined 

JS runtime environments

  • (outside webbrowser)
    • Node.js
    • stackblitz (VM): enables REPL (Read, Evaluate, Print Loop)

data/variable type

*important because you can use functions/methods just reserved for those specified types

  • Number
    • math.floor(), math.ceil(), math.round(), math.abs(), math.sqrt(), math.pow()
    • mathpow(2, 5) // returns 2^5
      5**7;
  • String
    • '+' -> turns everything into a string (ex. 1 + "1" = 11)
    • length, index
    • toLowerCase(), toUpperCase(), concat(), slice()
    • indexOf(): where the first letter of the value is located within the string
      • index starts at 0
    • includes(): see if the string includes the value
    • 'javascript'.length();
       'hello'.concat('benji'); // 'hello benji'
       'hello world'.slice(0, 5); // 'hello' 
       'where is benji'.indexOf('benji'); // 9
  • Boolean
    • falsy (false, 0, -0, 0n, "", '', ``, null, undefined, NaN), truthy
    • strict comparisons: ===, !==
    • loose comparisons: ==, !=
      • 12 == '12' //true
    • OR, AND, NOT
      • true || false // true
        false && true // false 
        !'' // true
        !'codestates' // false

variables

  • 'declaration', 'assignment' can be done at the same time
  • 'expressions' use variables for operations(?)
  • useful for avoiding repetitive tasks (e.g. replacing values manually)
  • unassigned variables get auto-assigned as 'undefined'
  • const stops you from reassigning the variable
  • var appeared before let/const. avoid using it, problematic
  • naming conventions
    - $love, _love
    - MyLove: PascalCase, my_love: snake_case, myLove = camelCase
  • template literal
    - enables you to insert a variable inside a string -> super readable!

//practice 
console.log(Math.floor(1843.123));
console.log(Math.sqrt(4));
console.log(Math.pow(3, 4));
console.log('최초의 JavaScript는 Netscape의 Brendan '.length);
console.log('where is benji'.indexOf('benji'));
console.log(!'codestates');


let FirstName = 'Kylian';
let MiddleName = 'A';
let LastName = 'MBappe';

console.log(`${FirstName} ${MiddleName} ${LastName}`);
console.log(`My name is ${FirstName} ${LastName}, and my middle name is ${MiddleName}.`);
profile
la, di, lah

0개의 댓글