We all have an idea of what our perfect computer looks like, and of course, more important, what components make it. Do you want a great processor? fast graphics card? Great cooling system?
Tell us, which one would be the PERFECT computer for you?
So this a very simple little program. It has a function that's going to print a string that's sent to it, and basically, it copies whatever's passed into it to a variable. And then it prints it out. Now, I am trying to print the variable whatToPrint outside of the print function. So what do you guys think's going to happen? Well It should blow up, right?
And guess what, it doesn't !
Well, what happens here is when this print function runs, it runs through this function and it gets to line four and it sees that variable whatToPrint and there is no var keyword in it.And there the runtime goes up to the scope and it says, "Hey, I have an LHS reference for whatToPrint. Do you have it?"
And the global scope will say, "I do not have one.But you probably intended to make one and you just forgot. So, guess what, I'm going to make it for you." .
And that then starts leaking things up to the global scope.
Just to quickly sum this up - if you forget to put a 'var' in front of a variable when you're declaring it, that variable gets leaked all the way up to global scope. Which is probably not what you intended to do.
So the key takeaway is don't forget to define your variable without var. But sometimes it may happen that you accidentally missed to put the var keyword. 🤔
If you guys know then it's awesome, let everyone know in the comments down below! 📱
Patrick Bet David!!! The CEO of the fastest growing financial markerting organization in America, PHP (People Helping People), and he runs the #1 entrepreneur page on youtube. His page has 960k followers just shy of 1 million!!! This Saturday, Oct. 20th, Patrick will be speaking at The Oddesey in Granada Hills for his 40th birthday and the 9th annerversy of PHP!!! There is so much value to gain from this great man! DM if interested in sitting down in front of man who's net worth is 70 million.