¡GoConqr estrena diseño! Cuéntanos qué te parece.

Fichas

Programming Basics - Modul 1

Viktoria Bzdyk Alemán 45 fichas

Fichas del conjunto (45)

  1. 1What is the purpose of the array (list in some programming languages) data structure? Name some methods of it!An array stores a collection of items. Available methods:
    .concat();
    .slice();
    .filter();
    .every();
    . reverse();
  2. 2What are the differences between a list/array and a set?The biggest difference between an Array & Set is that Arrays can have duplicate values whereas Sets cannot. The other big difference is that data in an array is ordered by index whereas Sets use keys & the elements are iterable in the order of insertion.
  3. 3What are the purpose and some methods of a dictionary/map data structure (simple data objects in JavaScript)?A dictionary is a general-purpose data structure for storing a group of objects. It has a set of keys and each key has
    a single associated value - When presented with a key the dictionary will
    return the associated value. Other names for it are hash, map,
    or hashmap. Some Methods are:
    – search
    – insert
    – delete
  4. 4Write a method (or pseudocode) that generates the Fibonacci sequence.The sequence has to be build like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
    (the first 2 are 0 and 1, the next is the sum of the previous 2)
    -> In nature, it describes a form of growth (animals, plants, etc.)
    let n1 = 0;
    let n2 = 1;
    let maximumNumber = 50; //or as desired
    let fiabonSequ = [n1, n2];
    function fiabonacciSequence () {
    for (let i = 0; i < maximumNumber; i ++) {
    let newNum = fiabonSequ[i] + fiabonSequ[i + 1]
    fiabonSequ.push(newNum);
    }
    return fiabonSequ;
    }
  5. 5How do you find a max value in a list/array if you can’t use any built-in functions or methods?Loop through the array and compare the items -->
    check if num at index = 0 is bigger than the one at index = 1 and save the bigger one in a different variable
  6. 6How do you find the average of values in a list/array if you can’t use any built-in functions or methods?Use simple mathemathics and iterate through the array - add every number to find the sum and divide it through the number of items in the array (array.length)
  7. 7What do we call an in-place sort?In-place algorithms are algorithms that do not require any additional data structure to transform the input data. Basically, this means that the algorithm does not require any additional space for input manipulation. It practically overwrites the input with the output.
    --> It changes the input to the output instead of generating new output data
  8. 8Explain an algorithm which sorts a list!Sorting algorithms are a set of instructions that take an array or list as an input and arrange the items into a particular order.
    Sorts are most commonly in numerical or a form of alphabetical (or lexicographical) order, and can be in ascending (A-Z, 0-9) or descending (Z-A, 9-0) order.
  9. 9Explain the characteristics of the procedural programming paradigm.Procedural means that the task/code/programm is split into smaller tasks to make it easier to work with. Those smaller bits are called procedures and procedural programming is part of nearly every imperative programming language. Some characteristics are:
    - local and global variables
    - predefined functions from a library
    - parameter passing
    - modularity (dividing code into smaller bits)
    - top-down approach (primary goal is defined first)
  10. 10What is the call stack?The call stack keeps track of functions to be executed. When we call a function, it’s added, or pushed to the top of the call stack. When the function returns, it’s removed, or popped from the call stack. Any asynchronous functions (fetch, setTimeout, async, etc.) are moved to the event queue (more on that later).
    Most likely, you’ve seen the call stack in your console when an error is thrown.
    You might have heard that JavaScript is single-threaded. This means it has only one call stack and it can only process one statement at a time. The call stack follows the LIFO (Last In, First Out) principle, which means it will always process the call on top of the stack first.
  11. 11What is "stack overflow"?Stack Overflow is a question and answer website for professional and enthusiast programmers. It features questions and answers on a wide range of topics in computer programming. It was created to be a more open alternative to earlier question and answer websites such as Experts-Exchange.
    The website serves as a platform for users to ask and answer questions, and, through membership and active participation, to vote questions and answers up or down similar to Reddit and edit questions and answers in a fashion similar to a wiki. Users of Stack Overflow can earn reputation points and "badges"; for example, a person is awarded 10 reputation points for receiving an "up" vote on a question or an answer to a question, and can receive badges for their valued contributions,which represents a gamification of the traditional Q&A website. Users unlock new privileges with an increase in reputation like the ability to vote, comment, and even edit other people's posts.
  12. 12What are the main parts of a function?- function keyword
    - function body and statements inside of it
    - the name of the function
    - parameters in the paranthesis
  13. 13What is the difference between parameters and arguments?Function parameters are the names listed in the function's definition. Function arguments are the real values passed to the function. Parameters are initialized to the values of the arguments supplied.
  14. 14What does it mean that a type is immutable? Tell examples.An immutable object (unchangeable object) is an object whose state cannot be modified after it is created.
    JS: const GRAVITATION_ON_MOON = 23,45
  15. 15What does it mean that an object is mutable? Tell examples.Mutable objects can be modified (or mutated) after they’re created, and transform into other data or variables.
    For example, an array can be changed to a string or a string to a number.
  16. 16What is a conditional expression?In computer science, conditionals are programming language commands for handling decisions.
    eg. if - else statements
  17. 17What are different types of arguments?In JavaScript, there are several different types of arguments that can be passed to a function:
    - Positional arguments
    - Default arguments
    - Rest arguments
    - Spread operator arguments
    - Named arguments
    - Destructured arguments:
    It's worth noting that JavaScript also supports optional arguments in a function, which are the arguments that do not have to be passed to the function when it's called.
  18. 18What is variable shadowing?In computer programming, variable shadowing occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope.
    This outer variable is said to be shadowed by the inner variable, while the inner identifier is said to mask the outer identifier.
    This can lead to confusion, as it may be unclear which variable subsequent uses of the shadowed variable name refer to, which depends on the name resolution rules of the language.
  19. 19What can happen if you try to delete/add an item from/to a list, while you are iterating over it?Removing items can cause the loop to skip elements of the list without meaning to. Adding items may cause the loop to view the same list item more than once. Of course this depends on the index of the item that you're removing, but in general the more you change the list, the more you throw off the loop's count. The problems this creates can be subtle, and therefore difficult to track down.
  20. 20If you need to access the iterator variable after a for loop, how would you do it?1. Declare the iterator variable outside the for loop: By declaring the iterator variable before the for loop, it will be in the same scope as the for loop, and you can access its value after the loop has completed.
    2. Declare the iterator variable as a let variable: By using the let keyword to declare the iterator variable, the variable will be block-scoped, and you can access its value after the loop has completed.
  21. 21What type of elements can a list contain?JavaScript arrays can indeed contain any and all types of data. An array may contain other objects (including other arrays) as well as any number of primitive values like strings, null , and undefined . When you place an object inside of another object, it's called a nested object.
  22. 22What can the + operator be used for?- for the addition on two operands.
    - to concatenate 2 strings
  23. 23What is string formatting?String formatting is a way to format string to make them easier to use. This is done by template literals - Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded expressions, and special constructs called tagged templates.
    eg: let output = `My name is ${name} and I am ${years} old`
  24. 24Name 4 iterable types.- Array
    - Map
    - String
    - Set
  25. 25Does the order of the function definitions matter? Why?The order of functions matters, when a variety of functions exist inside multiple scopes of a program. For a JavaScript program to perform correctly, functions in the inner scope must be able to access functions in the outer scope.
    -> BUT: The JavaScript compiler will process function declarations upon entry into an executable context e.g the global scope or a specific function call.
    -> Once these functions are processed any subsequent calls of these functions will be able to be invoked correctly regardless of the order of when they are called.
    -> The order of functions starts to matter hugely when functions are declared and invoked inside other functions (these are also called closures).
  26. 26What is spread/rest syntax for?- for iterable objects, like Arrays
    - to be expanded in places where zero or more arguments or elements are expected
    - Spread syntax looks exactly like rest syntax
    - Spread syntax "expands" an array into its elements, while rest syntax collects multiple elements and "condenses" them into a single element.
    - Rest syntax: A function definition's last parameter can be prefixed with ... , which will cause all remaining (user supplied) parameters to be placed within an Array object.
    - The main difference between rest and spread is that the rest operator puts the rest of some specific user-supplied values into a JavaScript array. But the spread syntax expands iterables into individual elements.
  27. 27What does a destructuring assignment mean?The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
  28. 28What happens when you try to assign the result of a function which has no return statement to a variable?the variable is undefined, because every function without return is undefined.
  29. 29What techniques can you use while debugging a program?- Simplify the complex data
    - Divide and conquer
    - Slow down the process
    - Change only one variable at a time
    - Identify the problematic part
    - start from a known-good state.
  30. 30What does step over, step into and step out mean when using the debugger?- Step in: means that if there is a function call, it goes inside the function and you can see how the function is executing line by line till it returns and you go back to the next line right after the function call.
    - Step over: means that if there is a function call, it just executes it like a black box and returns the result, but you cannot see how the function was executed.
    - Step out: means that if you have Stepped in a function and now you want to skip seeing how the rest of the function is going to execute, you Step out and the function returns. Then, you go back to the next line, that is the line right after the function call.
  31. 31How can you start to debug a program from a certain line using the debugger?define a breakpoint: To set a simple breakpoint in your code, select the far-left margin next to the line of code where you want to suspend execution. You can also select the line and then select F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert Breakpoint. The breakpoint appears as a red dot in the left margin next to the line of code. The debugger suspends execution just before the line runs.
  32. 32What are the advantages of using a version control system?Using version control software is a best practice for high performing software and DevOps teams. Version control also helps developers move faster and allows software teams to preserve efficiency and agility as the team scales to include more developers.
    - long-term change history -> tracability
    - makes code scalable and allows more people to work with it
    - branching and merging
  33. 33What is the difference between the working directory, the staging area and the repository in git?- The working area is like your scratch space, it's where you can add new content, you can modify delete content, if the content that you modify or delete is in your repository you don't have to worry about losing your work.
    - The staging area, that's what files are going to be a part of your next commit. It's how Git knows what is going to change between the current commit and the next one.
    - repository in git: the final version you uploaded
  34. 34What are remote repositories in git?Remote repositories are versions of your project that are hosted on the Internet or network somewhere.
  35. 35Why does a merge conflict occur?Merge conflicts happen when you merge branches that have competing commits, and Git needs your help to decide which changes to incorporate in the final merge. Git can often resolve differences between branches and merge them automatically.
  36. 36Through what series of commands could you put a new file into a remote repository connected to your existing local repository?1. git init
    2. git status
    3. git add -A if you want to add all the files
    4. git commit -m "Message"
    5. git remote add origin
    6. git checkout -b "branch_name"
    7. git push -u origin branch_name
  37. 37What does it mean atomic commits and descriptive commit messages?- atomic commit is an operation that applies a set of distinct changes as a single operation.
    - The guideline of a descriptive commit message is you should at least know what were you working with just by reading the commit message. The convention is usually using imperative sentences, and present tense.
    eg: add hamburger menu for mobile
    Even without looking at the code changes, you can generally know what is going on.
  38. 38What’s the difference between Git and GitHub?Git is not Github. Git is the version control software, and Github is a git repository hosting service which offers all the source code management provided in git. Github is where you upload your git repository.
  39. 39What does clean code mean?Clean code is a reader-focused development style that produces software that's easy to write, read and maintain. Developers are often tempted to consider their work complete when the application operates as expected. But we're not merely writing code for computer consumption - also for humans.
  40. 40What steps do we usually do during a clean code refactoring?- give variables and functions meaningful names
    - create small methods
    - DRY - Dont repeat yourself!
    - avoid code comments if unecessary
  41. 41What is error/exception handling?Exception handling is the process of responding to unwanted or unexpected events when a computer program runs. Exception handling deals with these events to avoid the program or system crashing, and without this process, exceptions would disrupt the normal operation of a program.
  42. 42What are the basics of exception handling in JavaScript?Different errors may occur while executing a JavaScript code. There are three types of errors.
    - Syntax Errors: These are errors that cannot be interpreted by the computer. These errors stop the program from working.
    In JavaScript, these errors are:
    Spelling errors (wrong spelling such as fiction instead of function).
    The omission of important characters, such as not using a semicolon to end a statement.
    Use of the wrong indentation.
    - Runtime Errors: These errors take place during execution. The errors get detected when your program runs. It crashes or raises an exception. Thus, exception handlers handle exception errors.
    These errors are often caused by:
    The program not being able to find data because it does not exist.
    The data being an invalid type of data.
    - Logical Errors: These types of errors do not throw an error or an exception at all. This is because they result from the code not doing what the developer intends it to. It’s challenging to find logical errors. They can only be found through thorough testing.
  43. 43In which case should we catch an exception? Why?Always
  44. 44What can/should we do with an exception in the `catch` block?In the catch block of a JavaScript try-catch statement, you can perform several actions to handle an exception:
    - Log the error
    - Notify the user
    - Retry the operation
    - Fallback to a default value
    - Exit gracefully
    - Re-throw the exception
    It's important to keep in mind that when handling exceptions it is important to be specific and only catch the exceptions that you know how to handle and let the rest to bubble up to a higher level of the call stack. Additionally, it's important to log the exception before handling it, in case the handling of the exception fails.
  45. 45What does the `finally` statement do in a `try-catch` block in JavaScript?The try statement defines the code block to run (to try). The catch statement defines a code block to handle any error. The finally statement defines a code block to run regardless of the result.

Información

Descripción
Fichas sobre Programming Basics - Modul 1, creado por Viktoria Bzdyk el 27/11/2021.
Creado por
Viktoria Bzdyk
Visitas
4
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?