LIKELION🦁 TIL(2022-06-22)

RyuΒ·2022λ…„ 6μ›” 23일
0

λ©‹μŸμ΄ μ‚¬μžμ²˜λŸΌ

λͺ©λ‘ 보기
6/12
post-thumbnail

Cμ–Έμ–΄

λ°œμ „

πŸ’‘ 1μ„ΈλŒ€ : ν•˜λ“œμ½”λ”© β†’ 2μ„ΈλŒ€ : while λ¬Έ β†’ 2.5μ„ΈλŒ€ : for λ¬Έ β†’ `3μ„ΈλŒ€ : ν•¨μˆ˜` β†’ 3.2μ„ΈλŒ€ : ν•¨μˆ˜ μœ μ—°ν™”(λ§€κ°œλ³€μˆ˜)

ν•¨μˆ˜

  • main() ν•¨μˆ˜ μœ„μ— λ§Œλ“€κΈ°.
    ν•¨μˆ˜ μ‹€ν–‰ μ‹œ β†’ μœ„μͺ½μœΌλ‘œ 이동해 ν•¨μˆ˜ μ‹€ν–‰ν•˜κ³ , λ‹€μ‹œ μ›λž˜ μ½”λ“œλ‘œ μ΄λ™ν•œλ‹€.
  • 자주 μ“°μ΄λŠ” pattern 을 λ³„λ„μ˜ 블둝에 넣어놓고, 이름을 λΆ™μ΄λŠ” 것.
  • ν•¨μˆ˜ μ΄λ¦„λ§Œ λ³΄μ•˜μ„ λ•Œ, 무슨 κΈ°λŠ₯을 ν•˜λŠ” 것인지 μ§κ΄€μ μœΌλ‘œ 이해할 수 μžˆμ–΄μ•Ό 함. (맀우 μ€‘μš”)
  • μžλ°” : testPrint(); Camel Case
    Cμ–Έμ–΄ : test_print(); Snake

μ§€μ—­λ³€μˆ˜

  • ν•΄λ‹Ή μ§€μ—­μ—μ„œλ§Œ μ‚¬μš©μ΄ κ°€λŠ₯ν•œ λ³€μˆ˜.
  • 일반 μ§€μ—­λ³€μˆ˜ (ν•¨μˆ˜ λ‚΄μ—μ„œ μ‚¬μš©ν•œ λ³€μˆ˜)
  • λ§€κ°œλ³€μˆ˜ void hello(int limit) { }

μ¦κ°μ—°μ‚°μž

int main() {
	int b = 10;
	int a = 10 + (b++);  // a = 20;
  printf("%d", b);   // b = 11;
  return 0;

return

  • return 의 μ˜λ―ΈλŠ” 변신이라고 μƒκ°ν•˜λ©΄ 쉽닀.
    즉, ν•¨μˆ˜μ—μ„œ 값을 return ν•˜λ©΄μ„œ κ·Έ κ°’μœΌλ‘œ λ³€μ‹ ν•˜λŠ” 것.
  • return λ§Œλ‚˜λ©΄ 무쑰건 ν•¨μˆ˜ μ’…λ£Œ.
  • void functionName() { } β†’ return μ‚¬μš©ν•΄λ„ 됨.
    β†’ return 10; κ³Ό 같이 κ°’ return 이 μ•ˆλ˜λŠ” 것.
    β†’ void μ—μ„œ return 은 ν•¨μˆ˜ μ’…λ£Œλ₯Ό μ˜λ―Έν•œλ‹€.
  • ν•¨μˆ˜μ— int, char κ³Ό 같이 데이터 νƒ€μž…μ„ 써야 ν•œλ‹€.

🐀 return 의 μ’…λ₯˜

  1. return 0; // 0 μ΄λΌλŠ” 인자 return. λ¬Έμ œκ°€ μ—†μ—ˆλ‹€.
  2. return 1; // 1 μ΄λΌλŠ” 인자 return. λ¬Έμ œκ°€ μžˆμ—ˆλ‹€.
  3. return; // κ·Έλƒ₯ ν•¨μˆ˜ μ’…λ£Œλ₯Ό μ˜λ―Έν•œλ‹€.

λ¬Έμ œν’€μ΄

μ†Œμˆ˜ 체크 문제.

// 문제 : μ†Œμˆ˜μΈμ§€ μ•„λ‹Œμ§€ μ²΄ν¬ν•˜λŠ” ν•¨μˆ˜ κ΅¬ν˜„

#include <stdio.h>

#pragma warning (disable: 4996)

int isPrime(int number) {
  if (number <= 1) {
    return 0;  // μ†Œμˆ˜κ°€ μ•„λ‹ˆλ‹€! 
  }
  for(int i=2; i*i<=number; i++){
    if(number % i == 0) {
      return 0;
    }
  }  
  return 1;   // μ†Œμˆ˜μž„!
}

int main(void) {
  printf("%d\n", isPrime(7));
  return 0;
}

μ•„μŠ€ν‚€ μ½”λ“œ

char a; // 1byte. λ¬Έμžκ°€ μ•„λ‹ˆλΌ 사싀상 β€˜μ •μˆ˜β€™κ°€ μ €μž₯λ˜λŠ” 것.
char c = β€˜a’; β†’ aλŠ” μ•„μŠ€ν‚€ μ½”λ“œν‘œ 상 μ •μˆ˜ 97이닀.
char c = 97; β†’ 차이가 μ „ν˜€ μ—†λ‹€. μ•„μŠ€ν‚€ μ½”λ“œ 상 β€˜a’ == 97 은 trueλ‹€.

printf(”%c”, 97); β†’ aκ°€ 좜λ ₯.


HTML, CSS

μ΄λ²ˆμ—λ„, 메뉴 μ•„μ΄ν…œ μ‹œκ°„ 재보기.

  • 3μ°¨ λ©”λ‰΄κΉŒμ§€ κ΅¬ν˜„ν•  수 μžˆμ–΄μ•Ό 함

Flex

β†’ μ°Έκ³  링크 μ—¬κΈ°

flex-container

  • flex-direction (default λŠ” row)
  • flex-wrap
    • nowrap : μ€„λ°”κΏˆ ν—ˆμš© μ ˆλŒ€ μ•ˆν•¨.
    • wrap : μ€„λ°”κΏˆ ν—ˆμš©ν•¨
  • align-items (column μ„€μ • μ—†μœΌλ©΄, 수직 μ •λ ¬)
  • align-content β†’ 두 쀄뢀터 μ‚¬μš©ν•˜λŠ”λ° μ˜λ―Έκ°€ μžˆλ‹€.
    • 즉, flex-wrap : wrap; 인 μƒνƒœμ—μ„œ μ‚¬μš©.
      nowrap 이면 ν•œ 쀄이기 λ•Œλ¬Έμ— 적용 μ•ˆλ¨.
  • align-self β†’ κ°œλ³„ μ •λ ¬.
  • justify-content (column μ„€μ • μ—†μœΌλ©΄, μˆ˜ν‰ μ •λ ¬)
  • order β†’ μˆœμ„œ 값을 μ€˜μ„œ, λ†’μœΌλ©΄ 맨 λ’€λ‘œ 배치.
    (μ²˜μŒμ—λŠ” 0 이 default 값이닀.)

space-between, space-around 의 차이점.

  • space-between
    β†’ 였직 μ‚¬μ΄μ—λ§Œ 생김.
  • space-around
    β†’ μ–‘ μ˜† 주변에 λ‹€ 생김.

inline vs css

  • 무쑰건 inline 속성이 이긴닀(μš°μ„ ν•œλ‹€).
  • κ·ΈλŸ¬λ‚˜ μ˜ˆμ™Έμ μœΌλ‘œ !important κ°€ λΆ™μœΌλ©΄ css κ°€ μš°μ„ ν•œλ‹€.
    β†’ inline에도 !important κ°€ λΆ™λŠ”λ‹€λ©΄ μ—­μ‹œλ‚˜ 무쑰건 inline 속성이 μš°μ„ ν•œλ‹€.

Javascript

DOM 으둜 event μΆ”κ°€ν•˜κΈ°

console.clear();
const button = document.querySelector("button:nth-child(2)");

button.addEventListener("click", function() {
  conosole.log("Hello World");
});

BOM : Browser Object Model

  • alert('hi');
  • window.close(); 와 window.open('');
    DOM : Document Object Model
  • querySelector();

JQeury

❓ μ œμ΄μΏΌλ¦¬κ°€ ꡬ식이고 μ™ λ§Œν•˜λ©΄ 쓰지 말아야 ν•œλ‹€ ? πŸ’‘ κ²°λ‘  : μ œμ΄μΏΌλ¦¬λŠ” `SPAμ—μ„œλ§Œ λ‚˜μœ 선택`이닀. 즉, μ œμ΄μΏΌλ¦¬λŠ” μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

🐀 μ™œ SPA λ₯Ό 쓰지 μ•Šμ„κΉŒ ?

  1. κ°œλ°œμ†λ„κ°€ 느림.
  2. λ‚œμ΄λ„ 상.
  3. κ³Όν•œ 고퀄리티 제곡. λ‹¨μˆœν•œ 정보, νšŒμ‚¬ μ†Œκ°œλŠ” ꡳ이 κ·Έλ ‡κ²Œ ν•  ν•„μš” μ—†λ‹€.

μ˜ˆμ „ 방식과 JQuery 비ꡐ

// μ˜ˆμ „ 방식
var div = document.getElementsByTagName('div');
for(var i = 0; i < div.length; i++) {
	div[i].style.backgroundColor = 'beige';
}
// JQuery
$('div').css('background-color', 'beige');
// 기타 (JQuery 쓰지 μ•Šμ„ λ•Œ)
document.querySelectorAll('div').forEach(e => e.style.backgroundColor = 'red'); 

jquery μ‚¬μš©ν•˜κΈ°.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

ν•¨μˆ˜μ˜ ν˜•νƒœ

// λͺ¨λ‘ λ‹€ ν•¨μˆ˜!!
function plus(a,b) { return a + b; }
const plus = function(a, b) { return a + b; }
const plus = (a, b) => {return a + b; }
const plus = (a, b) => a + b;

Javascript λ‘œλŠ” CSSλ₯Ό μˆ˜μ •ν•˜μ§€ 말자.

β†’ .css μ‚¬μš© 지양. (λ°˜λ“œμ‹œ 각 κΈ°λŠ₯에 μΆ©μ‹€ν•΄μ•Ό 함)

// 잘λͺ»λœ μ‚¬μš©.
console.clear();

$("button").click(function () {
  console.log($("body").css("background-color"));

  if ($("body").css("background-color") == "") {
    $("body").css("background-color", "#afafaf");
  } else {
    $("body").css("background-color", "");
  }
});

즉, λ‹€μŒκ³Ό 같이 μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

// μ˜¬λ°”λ₯Έ μ‚¬μš©.
console.clear();

$("button").click(function () {
  if ($("body").hasClass("bg-afafaf")) {
    // 가지고 μžˆλ‹€λ©΄
    $("body").removeClass("bg-afafaf");
  } else {
    $("body").addClass("bg-afafaf");
  }
});
		
// ν•¨μˆ˜λ₯Ό λ”°λ‘œ λΉΌμ„œ μž‘μ„±ν•΄λ„ λœλ‹€.
console.clear();

const a = function(){
  if($('body').hasClass('bg-afafaf')){
    $('body').removeClass('bg-afafaf');
  }
  else {
    $('body').addClass('bg-afafaf');
  }
}
$('button').click(a);
πŸ’‘ hasClass(), removeClass(), addClass() λŠ” **.bg-afafaf 라고 쓰지 μ•ŠλŠ”λ‹€**. κ·Έλƒ₯ bg-afafaf .
  • $(’body’).addClass(”a b c”); β†’ ν•œ λ²ˆμ— 3개 class 넣어쀄 수 있음.

.popup.active

  • .popup.active 의 μ˜λ―ΈλŠ” ?

    • 2개의 class λ₯Ό λ™μ‹œκ²Œ κ°–κ³  μžˆλŠ” μš”μ†Œ.
    • νŒμ—…μ°½μ—μ„œλŠ” .activeλ₯Ό λ„£κ³  λΉΌκ³  ν•˜λŠ” κ²ƒμœΌλ‘œ νŒμ—…μ°½ on/off .
    • .popup .active β†’ .popup μ•ˆμ— μžˆλŠ” .active μž„.
  • z-index : 1000; β†’ 유령 κ°„ κ²½μŸμ—μ„œ 이김. μš°μ„ μˆœμœ„λ₯Ό μ€˜μ„œ 맨 μ•žμœΌλ‘œ.
    즉, absolute; 속성끼리 κ²½μŸν•  λ•Œ 주둜 μ‚¬μš©ν•œλ‹€.

  • BEM : ν‘œμ€€ CSS λͺ…λͺ…법, λ§ˆν¬μ—… 방법
    header__box

preventDefault (BOM)

πŸ’‘ default event λ₯Ό 막아쀀닀. `return false;` 라고 해도 λ˜‘κ°™λ‹€. `event.preventDefault();` β†’ a νƒœκ·Έ 링크 이동 λ§‰μ•„μ€Œ, νΌμ—μ„œ submit λ²„νŠΌ 제좜 λ§‰μ•„μ€Œβ€¦ λ“±

alert 와 confirm (BOM)

  • window.alert(’hi’); 의 μ€„μž„ ν‘œν˜„. alert(’hi’);
  • confirm(’정말 μ‚­μ œν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?’); β†’ true or false λ₯Ό return.

이벀트 μ „νŒŒ

span β†’ nav ν•œν…Œ 보고 β†’ article ν•œν…Œ 보고 β†’ …

e.stopPropagation(); β†’ μ „νŒŒλ₯Ό λ©ˆμΆ˜λ‹€!

return false; β†’ e.preventDefault(); 와 e.stopPropagation(); 을 ν•©μ³λ†“μŒ.

profile
Strengthen the core.

0개의 λŒ“κΈ€