Code 301 Class 08 Reading Notes
Consepts of Functional Programming in Javascript
- What is functional programming?
Functional programming is a pragramming paraadigm - a style of building the structure and elemnts of computer programs - that treatscomputation as the evaluation of mathematical functions and avoids changing-state and mutable data
- Wikipedia ~ Reference - What is a pure function and how do we know if something is a pure function?
- What are the benefits of a pure function?
- It returns the same result if given the same arguments (it is also referred as deterministic)
- It does not cause any observable side effects
- What is immutability Unchanging over time or unable to be changed.
- What is Referentiality transparency If a function consistently yields the same result for the same input.
pure functions + immutable data = referential transparency
Node JS Tutorial for Beginners #6 - Modules and require()
- What is a module? A module is another JavaScript File.
- What does the word ‘require’ do? It passes a function from one module to another.
- How do we bring another module into the file that we are working in?
- Write out
require('')
, and withing the paranthesis and string is going to be a path to the module that we require in the file we are working in. - Then, write in the the file that we want to bring in with a dot and foward slash.
require('./count.js')
- Write out
- What do we have to do to make a module available?
- Write
module.exports =
which sets whatever we want to be made available outside of this module. - Write the function
counter
we would like to be available outside of this modulemodule.exports = counter;
- In thefile we want to pass to, create a variable to the require we are passing through
let counter = require('./count');
- Type in
node app
in your terminal, and thats how we create a module and how we require a module in another JavaScript file.
- Write