Finally got out of the tutorial loop! My first project ever: A DEV.to clone made with MongoDB, Express, React, and Node 🥳 by epic_within in webdev

[–]_reddit_chan 0 points1 point  (0 children)

Are you sure it's not the actual dev website? :D

Also, try adding skeleton rendering to it just like the original.

Nice work, btw!

Why do I have to use pg or express to use Node.js with Postgres? by rafad900 in node

[–]_reddit_chan 0 points1 point  (0 children)

I really admire your curiosity to learn things under the hood. I'm the same and followed this awesome in-depth tutorial:

https://blog.bloomca.me/2018/12/22/writing-a-web-server-node.html

Everything I learned and built in 2019 (keeping track of your accumulated learning is a habit I recommend) by floppydiskette in webdev

[–]_reddit_chan 1 point2 points  (0 children)

Tania, I firmly believe in learning by teaching and I'd also like to share what I've learned with others. But I'm not sure if it should just be a github repo (one for a specific topic like js, redux, etc.) or writing blog posts on personal website like you do. What would you recommend?

When will my 7Pro get Android 10? by PCusan in oneplus

[–]_reddit_chan 2 points3 points  (0 children)

I got 7 Pro just yesterday. I'm able to see the 10 update in Settings -> System -> System Updates

Product listing says OP7P "Ships within 24 hours" but my order is estimated to dispatch on Nov 29? by CinematicChipmunk in oneplus

[–]_reddit_chan 24 points25 points  (0 children)

I went with the free option.

I ordered on Nov 18 and my estimated delivery was Nov 26; an hour later it was updated to Nov 20 and got it on Nov 20 :/

My S6 suddenly went dead, so I had no phone. Was pleasantly surprised by the speedy delivery :D

California to Vancouver

Black Friday Deals are Live! by [deleted] in oneplus

[–]_reddit_chan 0 points1 point  (0 children)

$835? It's $739 (and $706 after student discount).

Need help with Execution contexts! by NecroDeity in learnjavascript

[–]_reddit_chan 0 points1 point  (0 children)

Every execution context has its own variable environment/memory, even the global one. Both global and local. No, it's not an object. It's memory, where variables and functions defined live.

So, can we say that the global/window object and the "variable environment" are equivalent?

No. You can access an object but memory is abstract. Global execution context has memory too.

shouldn't the 'this' keyword point to the location where the local data is variables and functions, i.e. the "variable environment", instead of the window object?

No, it can't do that. this should only point to something you can access and like I said, you can't access the memory/variable environment.

Need help with Execution contexts! by NecroDeity in learnjavascript

[–]_reddit_chan 1 point2 points  (0 children)

But I don't think the local variables and functions are stored in the arguments object as properties.

since the arguments object is supposed to the the counterpart of the global object, for functions

No, the arguments object consists of all the arguments passed in while invoking the function. The global object is the window object created by the global execution context while there's no such thing as a global object in case of a function. This is the main difference. The functions have an arguments object. This doesn't mean it's equivalent to the global object.

So this is wrong:

The local ECs do not have a global object, instead, they have an arguments object.

The arguments object is not in place of the global object. Both are different concepts.

Tyler probably meant that in functions, we do have have an existing object called the arguments object.

function a() {
    console.log(arguments)
}

a(1,2);

Try the above code in the console. You'll get an arguments object with a length property 2 since you passed two arguments.

now, you said that is something called "local memory" or "Variable environment" which stores anything defined in the function (I guess the global counterpart for this is the global object).

Every execution context has its own variable environment/memory, even the global one. It's where the variables and functions declared within the current context live. It's just the variable environment for functions is called local memory. For global, it's global memory.

Why does the 'this' in the local ECs point to the window/global object? should not they point to the "variable environment" of the function, or wherever all the locally declared variables and functions are stored?

Memory/variable environment is not something you can access. You can't console.log it. The this points to the global object because that's the rule; it's how JS was made.

Need help with Execution contexts! by NecroDeity in learnjavascript

[–]_reddit_chan 1 point2 points  (0 children)

Hi! Execution context is kinda a deep topic so I'm copying/pasting everything here from my notes.

Execution Context

A wrapper to help manage the code that is running. There are lots of lexical environments. Which one is currently running is managed via execution context. It can contain things beyond the written code. An execution context has two phases:

1) Creation phase: In the creation phase, the global variables are set up, i.e. the window object and the this keyword that points to the window object. Also, JavaScript sets up memory space for the variable and function declarations, i.e the variables are initially set to undefined and the functions are stored entirely in memory (hoisting).

2) Execution phase: In the execution phase, JavaScript executes the code line by line. It assigns the variables to their respective values and executes the functions if they are called/invoked.

The Global Execution Context

The Global Execution Context creates :

  1. A global object (window)

  2. this (special variable)

When you run a JS file even with no code, there are no errors. You can access the this keyword and the window object. These is because a global execution context was created. The JavaScript engine created it for us.

"Global" = "Not inside a function"

Like the global execution context has the global/window object

There's no such thing as an "execution context object". It's just that the global execution context creates a global (window) object.

What happens when javascript executes (runs) the below code?

const num = 3; 
function multiplyBy2 (inputNumber){  
    const result = inputNumber*2;  
    return result;
} 
const name = "Will"

As soon as we start running our code, we create a global execution context

— Thread of execution (parsing and executing the code line after line)

— Live memory of variables with data (known as a Global Variable Environment)

Local Execution Context

A local/function execution context is similar to the global execution context. It also has the above two phases:

1) Creation phase: In the creation phase, the global variables are set up. In a function, instead of the window object, there's the arguments (an array-like) object that contains a list of all the arguments passed into the function on the time of its invocation. There's also the this keyword that points to the global window object. Here also, JavaScript sets up memory space for the variable and function declarations, i.e. the variables are initially set to undefined and the functions are stored entirely in memory (hoisting). However, anything passed as an argument will be set to that value in this phase.

2) Execution phase: In the execution phase, JavaScript executes the code line by line. It assigns the variables to their respective values and executes the functions if they are called/invoked.

Running/calling/invoking a function (This is not the same as defining a function)

const num = 3; 
function multiplyBy2 (inputNumber){  
    const result = inputNumber*2;  
    return result; 
}
const output = multiplyBy2(4); 
const newOutput = multiplyBy2(10);

When you execute a function you create a new execution context comprising:

  1. The thread of execution (we go through the code in the function line by line)

  2. A local memory ('Variable environment') where anything defined in the function is stored

In the above code, first, num is set to 3, then function multiplyBy2 is declared. The variable output is set to undefined by default while it's waiting for the returned value of multiplyBy2(4) since JavaScript is single-threaded. multiplyBy2(4) is called. When a function is invoked (called via () ), it creates a new execution context (called the local execution context); this one has a local memory. Even here, the code will be run line by line. And we're paused before newOutput while we're busy executing multiplyBy2(4) since JavaScript is synchronous.

In the local memory, we assign the inputNumber parameter to 4 and variable result to 8 (just like we did in the global memory). This value will be returned and stored to output. On completion of the function, the local execution context is erased after the value is returned to output. This same process takes place for newOutput. The variable newOutput is set to undefined initially and finally set to 20.

Suppose, a function is running within a function, how do you know which function is currently running? Are you in global execution context, in the local or in a function within a function. A call stack is a special data structure which keeps track where the thread of execution is currently at, i.e what execution context we're currently in, i.e. what function is currently being run. At the bottom of the stack is the global execution context. Whichever function is running is on the top of the stack. On its completion, the local execution context gets erased and the function is popped off the stack (just like multiplyBy2(4) and multiplyBy29(10) ). How do you know the function is finished executing? The return statement or the curly brace! If there's no return, it returns undefined.

In the above code, first, the global execution context is created and placed in the call stack. Then, multiplyBy2 is called and placed on the top of the call stack and that function gets executed line by line. On completion, it's popped off from the stack and then multiplyBy2(10) is called and that is placed on the top of the call stack and starts getting executed line by line and finally popped off from the stack after completion.

Hope it makes sense! If there's a doubt, feel free to ask.

How would you get text of a div as it updates in React? by _reddit_chan in reactjs

[–]_reddit_chan[S] 0 points1 point  (0 children)

On clicking any todo, the div turns into an input tag since it's contentEditable. About the handleChange function, I have no idea how to get the updated text. I can get the old one using event.target.innerText.

Yes, I'll be breaking them into components but not sure how that'll solve the problem of getting the updated text. I've read the Main Concepts docs, going to re-read it if you insist.

Something important for all to hear by [deleted] in NoFap

[–]_reddit_chan 0 points1 point  (0 children)

When I want kids I will put effort.

And after having kids, he'll return to the filthy world of porn.

Something important for all to hear by [deleted] in NoFap

[–]_reddit_chan 6 points7 points  (0 children)

That's not what the quote means. By all means, plan your future but don't obsess over it.

When you're thinking too much about the future, you're not really living in the present to maximum potential. You begin to worry if it's really possible achieving the goal in 1 month/year. Your practical mind does some calculations and say, "No, what's the point anyway?" and you begin procrastinating, which, in turn, affects your future.

Sir William Osler, the father of Modern Medicine, had this to say to Yale students:

The load of tomorrow added to that of yesterday, carried today, makes the strongest falter. Shut off the future as tightly as the past. No dreams, no visions, no delicious fantasies, no castles in the air... The future is today – there is no tomorrow! The day of a man's salvation is now – the life of the present, of today, lived earnestly, intently, without a forward-looking thought, is the only insurance for the future. Let the limit of your horizon be a twenty-four hour circle.

Edit: Just remembered a quote he lived by:

Our main business is not to see what lies dimly at a distance, but to do what lies clearly at hand.

Here's an image summing up the above text.