Skip to content

Instantly share code, notes, and snippets.

View QuatoHub's full-sized avatar
🎯
Focusing

Hyeonjun Moon QuatoHub

🎯
Focusing
View GitHub Profile
function countAllCharacters(str) {
let obj = {};
for(let i = 0; i < str.length; i++){
if (obj[str[i]] === undefined) {
obj[str[i]] = 0
}
obj[str[i]]++
}
return obj;
}
function countAllLetters(str) {
let obj = {}; // 변수에 빈 객체 할당
for(let i = 0; i < str.length; i++){ // 반복문을 통해 인자로 받은 문자열 순회
if (obj[str[i]] === undefined) { // i번째 문자가 기존 객체의 키로 존재하지 않으면
obj[str[i]] = 0 // i번째 문자와 0을 새로운 키값으로 생성
}
obj[str[i]]++ // 해당 문자가 반복될 때 마다 1씩 값을 추가한다.
}
return obj;
}
// 문자열을 입력받아 문자열을 구성하는 각 문자를 키로 갖는 객체를 리턴
let output = countAllLetters('apple');
console.log(output); // --> {a: 1, p: 2, l: 1, e: 1}
console.log(score); // undefined
var core; // 변수 선언문
function foo() {
return;
{
}
// ASI의 동작 결과 => return; {};
// 개발자의 예측 => return {};
}
console.log(foo()); // undefined
console.log(10 / 0); //Infinity
console.log(10 / -0); //-Infinity
console.log(1 * "string"); // NaN
var first = "Hyeon-jun";
var last = "Moon";
// ES5 : 문자열 연결
console.log("My name is " + first + "" + last + ".");
// My name is Hyeon-jun Moon.
5 + 2; // 7
5 - 2; // 3
5 * 2; // 10
5 / 2; // 2.5
5 % 2; // 1
// ++ 연산자는 피연산자의 값을 변경하는 암묵적 할당이 이뤄진다.
x++; // x = x + 1;
console.log(x); // 2
// -- 연산자는 피연산자의 값을 변경하는 암묵적 할당이 이뤄진다.
x--; // x = x - 1;
console.log(x); // 1
// 동등 비교
5 == 5; // true
// 타입은 다르지만 암묵적 타입 변환을 통해 타입을 일치시키면 동등하다.
5 == "5"; // true