Home Icon

Week 3 Exercises - JS

  1. Name the three ways to declare a variable?
  2. let, var and const

  3. Which of the three variable declarations should you avoid and why?
  4. Avoid to use var because it has global scope and can cause hoisting problems.

  5. What rules should you follow when naming variables?
  6. The name of the variable must have meaning and if contains multiple words camelCase must be used

    The name or the variable must contain only letters, digitis, or the symbols $ and _

    The first character must not be a digit

    There are reserved words that cannot be used when naming variables

  7. What should you look out for when using the + operator with numbers and strings?
  8. The + operator is used to sum two values, but it can also be used to concatenate two strings.

  9. How does the % operator work?
  10. Returns the remainder of two operand.

  11. Explain the difference between == and ===.
  12. = compares the equity of two values without considering the type, while the === takes in consideration the type.

  13. When would you receive a NaN result?
  14. When the expected output type should be a number but is not

  15. How do you increment and decrement a number?
  16. Increment: ++
    Decrement: --

  17. Explain the difference between prefixing and post-fixing increment/decrement operators.
  18. When prefixing, the variable is incremented/decremented first and then the expression is evaluated using the new value of the variable.
    When post-fixing, the expression is evaluated and then the variable is incremented/decremented.

  19. What is operator precedence and how is it handled in JS?
  20. Determines the order in which the operator is processed

  21. How do you log information to the console?
  22. console.log()

  23. What does unary plus operator do to string representations of integers?
  24. Concatenates the two strings.

  25. What are the eight data types in JavaScript?
    1. Strings
    2. Numbers
    3. Objects
    4. Arrays
    5. Booleans
    6. NaN
    7. Undefined
    8. Null
  26. Which data type is NOT primitive?
  27. Objects

  28. What is the relationship between null and undefined?
  29. relationship between null and Undefined

  30. What is the difference between single, double, and backtick quotes for strings?
  31. "" and '' are used to create string literals, while the `` are used to create template strings.

  32. What is the term for embedding variables/expressions in a string?
  33. String Interplation

  34. Which type of quote lets you embed variables/expressions in a string?
  35. ``

  36. How do you embed variables/expressions in a string?
  37. string = `I am a ${typeof string}`;

  38. What is the difference between the slice/substring/substr string methods?
  39. slice(start, end) extracts a part of a string and returns the extracted part in a new string.
    substring(start, end) is similar to slice(), but the difference is that start and end values less than 0 are treated as 0
    substr(start, length) extracts a new string according to the length defined in the second property

  40. What are the three logical operators and what do they stand for?
  41. Or ||
    Not !
    And &&

  42. What are the comparison operators?
  43. == equal to
    === equal type and value
    != not equal to
    !== the value and type are not equals
    < less than
    > greater than
    >= greater or equal than
    <= less or equal than

  44. What are truthy and falsy values?
  45. Truly values are values evaluated to True in a Boolean Context
    Falsy values are values evaluated to False in a Boolean Context

  46. What are the falsy values in JavaScript?
  47. Undefined, Null, NaN, 0, ""

  48. What are conditionals?
  49. conditionals are blocks of code that only run if the condition is met

  50. What is the syntax for an if/else conditional?
  51. if(condition){
    //Run the code
    }else{
    //Run the code
    }

  52. What is the syntax for a switch statement?
  53. switch(expression){
    case(valueX):
    //Run the Code
    break;
    case(valueY):
    //Run the Code
    continue;
    }

  54. What is the syntax for a ternary operator?
  55. expression ? do this : do that

  56. What is nesting?
  57. Nesting is writing code inside of some other code like a function or a condition

  58. What are functions useful for?
  59. Functions are uselful to simplify repetitive tasks

  60. How do you invoke a function?
  61. funcName(params)

  62. What are anonymous functions?
  63. Anonymous functions are functions that have no name.

  64. What is function scope?
  65. The scope is related to where the variable is available. If the variable is created whithin a function, it will only be available "inside" the function.

  66. What are return values?
  67. The return values are the values that a function returns when it has completed.

  68. What are arrow functions?
  69. Arrow functions are a simplified and concise way to create functions.