 Tak, więc basicznie powinienem mieć mnóstwo, ale to nie działa, bo to jest technologia. Także, będę wyobraził trochę. Dzień dźwięk, nazywam się Foks i rozmawiamy o czerwowskim interwju Skoping i Hoisting. Pytam pytanie. Tak, w tym razie, co będzie konsollokowane, kiedy mam komentarz na konsollokę? Zobaczmy kod, mamy 10 sekund, 2, 1, ok. Tak, kto wie? Nie ma miejsca. 5, tak? Ok, kto thinks it's 1? Kto thinks it's something different, another idea is undefined, tak? 1 person thinks undefined, who has another idea? Tak? 10, ok. It's going to be 10. Więc, jeśli nie rozumiecie dlaczego powinniście słyszeć dźwięk, to bardzo biorąc, że nikt nie wie. Nikt nie wie, nikt nie wie, tak. Dzień dźwięk z digitala Detox, zapomniałem o twoim nazwie. Aleks, tak, to ciężko. I tak, zacznijmy... Zobaczmy później. Potem rozumiemy dlaczego to jest 10. Więc skop to jest wizje w jednej części programu do innej części programu. Szybko, wizje i metody i konstancje, które są w jednej części programu do innej części programu. Więc jeśli są w jednej funkcjonie, to są w innej funkcjonie i tak dalej. Więc... Więc ja zrozumiem, że jest to variable A. Jeśli nie zrozumiałeś, że to jest w actualnym programu JavaScript. Przyzwyczaj, czekaj, skop A do B. I nie chcę tego do konsolokowania. Więc co to będzie skop A? Jamie. Skop A. Tak, to jest variable A. W 947 w moim kodzie. Tak, tak. Co to jest current lexicalne skop? Programu z początku. Tutaj zaczyna się. Szczerze, że pokażę każdą stronę programu. I teraz tutaj definiuję variable A. Current lexicalne skop, bardzo smutne odpowiedzi. Ale... To jest jeszcze odpowiedzi. To jest jeszcze odpowiedzi. Tak? Tak, tak. Szybko, szybko, szybko, szybko, szybko. Tak, tak. Możesz to teraz? Szybko. Przepraszam, nie mogę w actualne. Daj mi jakieś opisy. Ok, ok. Wydaje mi odpowiedzi. Nie ma skręcia. I połatwę mój kurs do końca. Ok, gdzie mój kurs? Karso. Ja zawsze czekam, że chcąc pokazać kursy, są tak źle z komputerem. I teraz pokażę kurs, i nie mogę pokazać komputerom. I czekam się tak zmienione. Boom. Tak, ok. Rf6? Nie, nie. Rf5, tak. So expect scope of A to B. Mhm. It's global, yes. So you got a job because you're smart. But you don't know JavaScript. Eee... Yes. Now we have another variable. There's a function FB. It's a block statement, if statement. And there's a variable B. Expect scope of B to B. Functional scope. Correct. Ok, you guys are getting better. And you're learning quickly. And now This is actually Exactly. Because let is ES6. You define variables with let and constants with const. And in this case it's going to a block scope. So function scope is all this function. And block is actually this block it starts here. So it's going to be visible only in this block. So who knows why in ES6 so in the newest version of JavaScript they introduced a block scope. Why did they change it? Eee... Because of Dementia. That's the correct answer. Because for some people like me JavaScript is the best and the only language in the world that you should run on everything. But there are some other people like Java developers C sharp and they come to JavaScript and they are confused because JavaScript is different. And in most of object oriented languages there is a block scope so they made it a block scope so it's simpler for developers coming from other languages. Eee... That's why also they also raped JavaScript with other stuff like classical inheritance and you can cut this out, yes? And so there's a function d and a function fd I'm going to uncomment this console log What is going to be console locked? One second I'll get some water You need to think hard about this. What's going to be console locked? Ok, who knows this? Only a very smart person will know. It's gonna be an error. Who said it? Thank you. What's your name by the way? Olek. Ok And Node 1.js It's a reference error d is not defined Correct If it wasn't a yes, if it wasn't a strict mode that's why I added a new strict here JavaScript will automatically create this variable but it's 2016 so let's assume we are using a strict mode because it's more and more default and yes I'm going to uncomment this line What is going to be console locked now? Correct answer And now you're being how to call it, banned from giving answers to everybody It's undefined Why? Ok, ok I was kidding, yes. Why is it going to be undefined because of the hoisting Correct No, JavaScript has a very specific behavior called hoisting All variables and methods are being declared not defined It's important, declared, not defined and the top of their scope So in this case, what's happening I can show you at the moment I run the program and this is undefined, not an error anymore Because of hoisting All variables are being declared on the top of their scope This variable D has a function scope It's being declared in here and defined in here So when it's being declared here it's undefined So now this console lock is giving you undefined Thank you Simple And let me Just Go Now, if I run this hoisted function what's going to happen Foo Foo? Should be something nice, I need to change this code to Yeah, or something like smile Something like Foo sounds stupid Yes, it's going to Say foo Correct Why? Because As I said before Due to hoisting All functions and methods are being No, methods are being not only declared but defined at the top of their scope So actually All the hoisted and all these functions JavaScript is not seeing it here But it's seeing this On top of its scope So with all the other functions It's in the top of my file So even before the title That's where the function actually is So now Let's back to our quiz One person knew it's 10 And So I will explain you now why So We are in the function fx Do you okay I can now understand why it's 10 Okay One person Everybody should understand now Okay, I'm going to go home We have a variable x Here in this function But it's being declared At the top of this function What just happened? It's being Declared At the top of this function Yes X Here Here is being only defined So now I have X here And it's undefined So If not X Not Undefined Is equal to True Yes If you make it a Boolean Yeah X Is being defined as 10 And now what is going to be Consoloc is 10 And if you don't believe me I'm going to run this And it's 10 Thank you guys Any questions Yes I mean All the stuff is covered So it's I mean it's It's really important to run this So we can try this This kind of Code In real world You see what I mean Good winter won't allow you to Kind of use variable Before you declare it Yes Yes And you know If you run this As a part of your build system Or something like this You will always get this And there will be no such situation In production Correct That's why there's a title of the talk As Javascript Interviews As you know Oleg, when did you have an interview last time? I know you probably always get hired on the first interview But let's say you had a few Seven You must have been picky And So this is as Javascript That's why the first title of the talk Ok, basically what Oleg is saying Is that at the moment All professional companies on production Are running code linters And they won't allow you To do stuff like this Like this They won't allow you to do stuff like this Because they will know this is not Clean code And So this code won't go In production So I explained to Oleg Why the first talk Of the first title of the talk Was Javascript Back to Basics But then people were This is stupid These are not real life examples That's why I changed the talk To what was actually my goal I asked Javascript interviews So a place where stupid Is the goal I mean It's not to find the talk It's a cool talk Yes I agree Thank you Oleg I'm passing an advice from Oleg Everybody should use code linters Like JSHint For example And they won't allow you to write stupid code Any more questions? As I'm aware of not Are you aware of it? No So Javascript was written By a guy Bernard Aik Up till today He didn't tell anybody What was he thinking about when he wrote it And this is still a mystery In the history And If he will take it to his grave I would love to be there When he will be dying to ask these questions No I wouldn't like to see Javascript As the only language Because there are always Tasks for which Other languages Are better You have a task and choose the best tool For the language If you do machine learning And some data science To spite on But basically You can now a days Code everything in Javascript Javascript is being On everything Each computer in this room Is running in Javascript Because everything has a web browser Even if it doesn't So it runs in every web browser In the world Since 20 years And Serwers As Node.js All new IoT devices Basically word of Internet of Things devices Was always C and some Windows IDE And now it's all being All is moving to Node JS Just to make it simpler for developers Only some specific cases When you have a really Unpowerful device That is running on battery I still code it in C At the moment In few years Javascript will be On washing machine And you're free And of course your TV And it's obvious And what You code web servers You can now script nginx Which is one of the most popular servers in the world And using Javascript Because they just added scripting Like Google Docs Everything is going to Javascript It's the one language That you can do everything with And it's also functional programming In Javascript So it can be the only one I'm not telling that everybody should be using Javascript Everybody should be free On that note Another round of applause