[JavaScript] 함수로 숫자의 합과 문자열 갯수 구하기
함수(function) 함수는 작업을 수행하기 위한 코드 블럭으로 자바스크립트의 객체(함수와 변수의 연관된 것들을 그룹화하는 도구)이다. 함수로 두 개 숫자의 합 구하기 const a = 12345; const b = 67890; function sum() { console.log(a + b) } sum() //80,235 함수로 문자열의 갯수 구하기 const word = "JUST DO IT" function getStringLength() { console.log(word.length) }; getStringLength() //10
언어/JavaScript
2023. 7. 4. 14:43
[JavaScript] 문자열 길이 구하기
자바스크립트로 문자열 길이를 구할 수 있다. ex.1 const str = "EEE"; console.log(`${str.length}`); 결과값 : 3 ex.2 const word1 = 'green' const word2 = 'red' const word3 = 'black' const length1 = word1.length; const length2 = word2.length; const length3 = word3.length; console.log(length1 + length2 + length3) 결과값 : 13
언어/JavaScript
2023. 7. 4. 12:36
- Total
- Today
- Yesterday