21년 6월 11일 복기
function solution(s) {
let answer = '';
let index = 0;
for(let i =0; i < s.length; i++){
if(s[i] ===" ") {
index = 0;
answer += " ";
}
else {
if(index%2 === 0) {
//짝
answer += s[i].toUpperCase();
}else{
//홀
answer += s[i].toLowerCase();
}
index++;
}
}
return answer;
}
모든 자바스크립트 파일을 브라우저에서 한 번에 로딩 할 때의 문제점을 설명해주세요.
https://www.youtube.com/watch?v=zi-IG6VHBh8
자바스레드는 논블로킹이지만 싱글 스레드로
JavaScript is a single-threaded programming language, which means it has a single Call Stack. Therefore it can do one thing at a time.
“Blowing the stack” — this happens when you reach the maximum Call Stack size. And that could happen quite easily, especially if you’re using recursion without testing your code very extensively. Take a look at this sample code:
function foo() {
foo();
}
foo();
When the engine starts executing this code, it starts with calling the function “foo”. This function, however, is recursive and starts calling itself without any termination conditions. So at every step of the execution, the same function gets added to the Call Stack over and over again. It looks something like this:
At some point, however, the number of function calls in the Call Stack exceeds the actual size of the Call Stack, and the browser decides to take action, by throwing an error, which can look something like this:
Running code on a single thread can be quite easy since you don’t have to deal with complicated scenarios that are arising in multi-threaded environments — for example, deadlocks.
But running on a single thread is quite limiting as well. Since JavaScript has a single Call Stack, what happens when things are slow?
You may ask — why is this even a problem? The problem is that while the Call Stack has functions to execute, the browser can’t actually do anything else — it’s getting blocked. This means that the browser can’t render, it can’t run any other code, it’s just stuck. And this creates problems if you want nice fluid UIs in your app.
And that’s not the only problem. Once your browser starts processing so many tasks in the Call Stack, it may stop being responsive for quite a long time. And most browsers take action by raising an error, asking you whether you want to terminate the web page.
Author And Source
이 문제에 관하여(21년 6월 11일 복기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jtlim0414/21년-6월-11일-복기저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)