prestudy-week1

Sunghee Kim·2022년 4월 21일
0

1. 변수가 필요한 이유와 선언하는 방법.

A variable stores the data value that can be changed later on.
데이터를 저장하기 위해서.
const name1 = 'sunghee Kim'
keyword /variable name/ assign / value

2.자바스크립트 데이터 타입의 종류
기본타입:Number,String, Boolean, Undefined, Null
참조타입:Object, Array, Function

3.number와 string의 메서드 각각 3개와 사용방법

number method

1)toString()
정수값을 문자열값으로 변환하는 메서드 : 숫자 → 문자
The toString() method returns a number as a string.

2)toFixed()
소수점 자리로 반올림
The toFixed() method rounds a number to a given number of digits.

3)parseInt()
Parses its argument and returns an integer
실수일때 정수만 리턴
문자열 타입의 숫자를 정수로 변환하는 메서드
문자열을 파싱(분석)하여, 문자열로 된 부분 중 숫자만 찾아 뽑아서 변환
숫자로 변환할 수 없으면 NaN을 리턴
NaN = Not-A-Number (= 숫자가 아님 = 숫자로써 읽을 수 없음)

변수 num : 정수 2는 그대로 정수 2가 출력
변수 num2 : 문자 "2"는 정수 2로 변환되어 출력
변수 num3 : "2학년" 중에서 문자 "2"를 찾아 정수 2로 변환되어 출력
변수 num4 : 제일 앞에 문자열로 시작하는 경우에는 숫자를 찾지 못하여 NaN이 리턴됨.

string method

1).toUpperCase()
A string is converted to upper case with toUpperCase():
2).replace()
.replace('변환해야 할 문자열', '변환하고 싶은 문자열')
3).concat()
The concat() method joins two or more strings:
문자열을 이어붙이는 메서드.
문자열에 다른 문자열을 이어붙이고 싶을 때, concat()의 괄호 안에 ,(콤마)로 이어붙일 문자열 변수를 나열.

  1. 함수가 필요한 이유
    a function allows you to define a block of code, give it a name and then execute it as many times as you want
    동일한 코드를 여러 번 작성하는 방식보다 코드를 블록으로 그룹화하여 하나의 작업과 연결하여 효율적으로 재사용하기 위해.

  2. 함수의 정의와 호출의 차이점.
    Defining a function is the creation of a function.
    Passing the data it needs, executing the code inside the function and using the values it generates

  3. 조건문이 필요한 이유
    conditional statements work on the basis of true and false scenarios, which inform the decision for running a specific task.
    They are used for checking a specific condition and executing the code based on the specified condition.

profile
개발하는 스트롱맘

0개의 댓글