자바스크립트 변수

작성자

카테고리:

← 피드로
DEV Community · Jaisurya · 2026-08-12 개발(SW)

Jaisurya

In JavaScript, a variable is a named storage location that holds a value, which can be any data type, such as numbers, strings, boolean, etc. It can be declared using keywords like var, let, or const.

1.var
var is function scoped, it can be re-declared and reassigned.

if(true){
  var a = 10;
}
console.log(a);
//Output: 10

Enter fullscreen mode Exit fullscreen mode

2.let
let is block scoped, it can be updated , but can’t be redeclared in the same scope.

let x = 10;
if(true){
  let x = 35;
  console.log(x);
} 
console.log(x);
//Output:
35
10

Enter fullscreen mode Exit fullscreen mode

3.const
const is also block scoped, it can’t be updated, used to store constant values

const pi = 3.14;
let r = 2;
let c = 2 * pi * r;
console.log(c);
//Output: 
12.56

Enter fullscreen mode Exit fullscreen mode

원문에서 계속 ↗

추출 본문 · 출처: dev.to · https://dev.to/jaisurya/javascript-variable-i8p

코멘트

답글 남기기