I started a new therapist. My anxiety is high over this. I had an appointment today, virtual appointment. It was alright. Although I didn’t feel like talking about my past too much. It’s a good thing he has notes and asked me general questions about them to help. I know I have a lot of things to go through but I feel overwhelmed about it. I mean, how do I just bring up things about the past that I don’t like to talk about? He gave me his cell and a warm crisis line to text if I have any questions or having a crisis. Part of me feels like I don’t have any problems worthy of needing therapy. Yes, I know that is crazy and I would never tell anyone they don’t need therapy if they feel like they need help. I know I have a lot of things that warrants therapy. It’s just having a new therapist kind of terrifies me. I felt that I didn’t talk about too many things today…but then today was just an assessment and it was only one day. Opening up is hard for me. I know they are not there to judge. But I have a problem with judging myself. My next appointment is next week. I wonder how that one will go? Also, I’ve never had a male therapist before. He seems nice so we will see how that goes.
I’m making spaghetti sauce right now. Well, it’s simmering. I want to bake something. Ok, I want to procrastinate from JavaScript cause it’s been a hard coding day. But I do want to bake something.
Happy Summer Solstice! My birthday is in five days. Wow.
JavaScript notes…
————————————-
Just like a regular function, you can pass arguments into an arrow function.
const doubler = (item) => item * 2; doubler(4);
doubler(4) would return the value 8.
If an arrow function has a single parameter, the parentheses enclosing the parameter may be omitted.
const doubler = item => item * 2;
It is possible to pass more than one argument into an arrow function.
const multiplier = (item, multi) => item * multi; multiplier(4, 2);
multiplier(4, 2) would return the value 8.
In order to help us create more flexible functions, ES6 introduces default parameters for functions.
const greeting = (name = "Anonymous") => "Hello " + name; console.log(greeting("John")); console.log(greeting());
The console will display the strings Hello John and Hello Anonymous.
The default parameter kicks in when the argument is not specified (it is undefined). As you can see in the example above, the parameter name will receive its default value Anonymous when you do not provide a value for the parameter. You can add default values for as many parameters as you want.
In order to help us create more flexible functions, ES6 introduces the rest parameter for function parameters. With the rest parameter, you can create functions that take a variable number of arguments. These arguments are stored in an array that can be accessed later from inside the function.
function howMany(...args) { return "You have passed " + args.length + " arguments."; } console.log(howMany(0, 1, 2)); console.log(howMany("string", null, [1, 2, 3], { }));
The console would display the strings You have passed 3 arguments. and You have passed 4 arguments..
The rest parameter eliminates the need to use the arguments object and allows us to use array methods on the array of parameters passed to the function howMany.
ES6 introduces the spread operator, which allows us to expand arrays and other expressions in places where multiple parameters or elements are expected. The ES5 code below uses apply() to compute the maximum value in an array:
var arr = [6, 89, 3, 45]; var maximus = Math.max.apply(null, arr);
maximus would have a value of 89.
We had to use Math.max.apply(null, arr) because Math.max(arr) returns NaN. Math.max() expects comma-separated arguments, but not an array. The spread operator makes this syntax much better to read and maintain.
const arr = [6, 89, 3, 45]; const maximus = Math.max(...arr);
maximus would have a value of 89.
…arr returns an unpacked array. In other words, it spreads the array. However, the spread operator only works in-place, like in an argument to a function or in an array literal. For example:
const spreaded = [...arr];
However, the following code will not work:
const spreaded = ...arr;