티스토리 뷰

Web/Back_java 기초

Java_기초

잉_민 2022. 2. 4. 09:51
728x90
반응형

[변수 할당]

  • let

    변수 재선언이 불가능 :초기화 후 변숫값을 계속 변경 가능

  • const

    변수 재선언이 불가능 :한번 초기화하면 다른 값을 대입할 수 없음.

[블락 스코프]

{ —- } 

변수는 메모리에 존재하는 공간 (메모리 - > 특정 주소)

그 공간은 정보를 저장하기 위해서 사용된다.

공간을 찾기 쉽게 만들려고 이름을 붙여 사용.

값들은 임시적으로 존재한다.

[글자 입력]

let tmepliteral = `안녕하세요 ${b}`//back tic??

var num1 =1
var num2 =2
var result= 3
var string1 = num1 + '더하기 '+num2+ '는 \''+ result + '\''
console.log('string1:',string1)
const string2 = `${null} 더하기 ${num2}는 '${result}'`
console.log('string2:',string2)

\' = ' 작은따옴표 치기 위해 역슬래시 필요하다.

${ xx }는 변수 이름

` 는 ~키 : 역 따옴표

[array : 배열]

<html>
  <body>
    배열
  </body>
</html>
<script>

//let A = new Array ('1','2','3','4') :: 튜브형식은 변환이 안 됨
const A = ['1','2','3','4']
console.log("배열",A)

</script>

배열의 인덱스  A [0] :: 순서 중요 / 0부터 시작한다.

A.push('0') : 마지막에 추가해준다.

A.pop('0') : 마지막에 추가해준다.

A[0] = '9' : 값을 바꿀 수 있다.

A.concat(B) :배열 합치기

//A.push('0') 마지막에 추가해준다.
//배열 합치기 A.concat(B)

const A = ['1','2','3','4']
console.log("배열",A)const person = {
  name : 'lee',
  age : '30',
  birthday : '92/06/27',
  array : [1,2,3],
  func : function () {
    return "객체안에 함수"
  },
  ob : {
    name : '객체안에 객체'
  }
}

console.log(person)
console.log(person.name)
console.log(person.birthday)
console.log(person['age'])
console.log(person.ob.name)
console.log(person.func())
console.log(person.array[0])//1


person['data'] =111; // 속성추가
console.log(person.data); // 111

[오브젝트 : 객체]

var zero = {
  키 : '밸류',
  키 : '밸류'
};
<html>
  <body>
    오브젝트
  </body>
</html>
<script>

const person = {
  name : 'lee',
  age : '30',
  birthday : '92/06/27'
}

console.log(person)
console.log(person.name)
console.log(person.birthday)
console.log(person['age'])

</script>
<html>
  <body>
    오브젝트
  </body>
</html>
<script>

const person = {
  name : 'lee',
  age : '30',
  birthday : '92/06/27',
  array : [1,2,3],
  func : function () {
    return "객체안에 함수"
  },
  ob : {
    name : '객체안에 객체'
  }
}

console.log(person)
console.log(person.name)
console.log(person.birthday)
console.log(person['age'])
console.log(person.ob.name)
console.log(person.func())
console.log(person.array[0])//1


person['data'] =111; // 속성추가
console.log(person.data); // 111 
</script>

 

[this]

object 아래 펑션에 this 를 넣으면

화살표일 경우 this = 오브젝트

화살표 아닐 경우 this = window

<html>
  <body>
    오브젝트
  </body>
</html>
<script>

var value =1

const obj = {
  value : 100,
  foo : function (){
      console.log("foo's this" , this);
      console.log("foo's this.value :", this.value);
      function bar(){
          console.log("bar's this:", this);
          console.log("bar's this.value:",this.value);
      }
      bar();
  }
};
obj.foo()


</script>

 

[구조 분해 할당]

배열

let array = ["Baram","lee"]

let [fistName,surname] = array;

consol.log(firstName) //lee

consol.log(fsurname)//baram

객체

const option = {
title : 'home',
width : 300,
hight : 500
}

//const title = option.title
//const width = option.width
//const hight = option.hight

const{title,width,hight} = option
//이름중요 *키값을 쓴다. *

console.log(title);
console.log(width);
console.log(hight);

*응용

const family = {
grandmother : 'Harrison',
sister : 'Ethan',
brother : 'Austin'
}


const{brother, sister : baby, grandfather = "할아버지"} = family


console.log(brother);
console.log(baby);
console.log(grandfather);

//Austin
//Ethan
//할아버지

sister 키값 할당을 baby로 한다

grandfather의 값을 추가하고 할당한다.

728x90
반응형

'Web > Back_java 기초' 카테고리의 다른 글

Java_async await  (0) 2022.02.04
Java_Promise  (0) 2022.02.04
Java_ 비동기/ 콜백 함수  (0) 2022.02.04
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함
반응형