Named Export and Import vs Default one

note - ./ is for same level while ../ is for one level up. ../../ is two level up.

Switch Statement

The switch statement is used to perform different actions based on different conditions.

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}

Example

const number = 2;
let result;

switch (number) {
    case 1:
        result = "I am One";
        break;
    case 2:
        result = "I am two";
        break;
    default:
        result = "I am another number";
}

console.log(result);

note : Dont forget to put break after every cases. Only the last case doesnt require break. Generally last case is default so people say after default break is not needed but if default is not at last then even default needs break.

Tasks

  1. Use Switch through days like 0 = Sunday, 1 = Monday, 2 = Tuesday and so on. If day = 0, then print It is Sunday.
  2. If grade of student is A+ - give remarks as “Excellent. You have done well.” and do it for all. A+. A, B+, B, C+, C, D, NG.

for in loop - not recommended for modern javascript

for (key in object) {
  // code block to be executed
}
for (let key in person) {
    console.log(key, person[key]);
}

Task - Create any two objects and use for in loop to display the key and value pairs.

When to use which?