Programming/Java Script

[K-MOOC x Coursera ] JavaScript Basic - Module 2

감귤밭호지차 2022. 11. 6. 01:08

이 수업에서는 Visual Studio Code 프로그램을 사용한다. 우선 시작하기 앞서 나같은 Window 사용자들은 파일들의 확장자 명을 볼 수 있게 설정해두도록 하자. 

 

<Window 확장자 명 보기 설정 >

파일 확장명 보이게 설정하는 방법

 

 

>> TIP : VS 새 폴더 만들 때 파일 이름에 공백은 없도록 하자.

 

## JS에서의 undefined / null / 0 는 FALSE

아래와 같이 코드를 작성해보면 chrome 화면 출력 결과는 False가 나온다. 

여기서 green은 값이 undefiend인 변수여서 출력하면 값은 false 이기 때문에 if문의 else 블록의 출력문이 출력된다. Undefined resolves this flase Java Script. (Undefined는 잘못된 JS를 해결해준다.) 

>> JS는 undefined / null / 0 / -0 false로 다룬다. 

 

Identify aspects of JavaScript that make it unique and sometimes challenging to write clear code. 

* The plus sign( + ) does double duty  - 출력할 때 + 부호를 사용해서 이어진 문장을 출력할 수 있다. 

   : The character is used to both add numbers and concatenate strings.Using template literals helps.

* Truthiness in JavaScript

   : This can be confusing and unclear, especially when combined with type coercion.

* JavaScrpt is loosely typed

   : This can be viewed as a negative aspect of JavaScript, but if you work with it properly, it is not such a big issue. 

 

## JS에서 특이 연산자 

>>  산술 연산자

1. ** [ 거듭제곱 ]

2 ** 3 = 8 //2의 3제곱

 

>> 비교 연산자

1. ==  [ 타입이 달라도 값이 같으면 True ] 

3 == '3' // true

2. === [ 타입도 값도 같아야 True ] 

3 === '3' //false
3 === 3   // true

3. != [ 타입은 상관없이 값이 다르면 True ] 

3 != '3' // true
3 != 4   // true

4. !== [ 타입도 값도 달라야 True ]

3 !== '3'  // true  : 타입이 다르기 때문에 
3 !== 4    // true

 

Add to read 

1. W3schools : JavaScript Operators 

2. W3schools : JavaScript Booleans

Add to read 

1. W3schools : JavaScript For Loop


## Sequence, Selection, and Loop 

 

From the options below, identify the answer that has three basic logic flow control structures. 

A : Sequence, selection, loop 

>> These three structures control the flow of logic in modern programming language. 

 


1. 사용자로부터 입력 값 받기 : prompt( )

 

< html + JavaScript 코드 예제 >

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My file</title>
</head>
<body>
    <h1>JavaScript Basic challenges</h1>
    <h2>Challenge 1</h2>

    <script>
        var name = prompt("What's your name?", "");
        console.log(`Hello ${name}, and welcome!`);
    </script>
    
</body>
</html>

< 사용자가 보는 화면 >

 

이제 저 입력 칸에 ( Bob ) 이라고 입력을 해주면 다음 사진과 같이 출력된다. 

 

 

 


## Function