script_type

지원·2025년 9월 15일

웹프레임워크

목록 보기
1/3
post-thumbnail

script type 차이

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width"/>
  <meta charset="utf-8">
  <title>object and this</title>
  <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>
<body>
<h1>Arrow Functions</h1>
<p>Open the console</p>
<script type="module">

script태그 안 type 속성 중 module, javascipt, babel 차이 알아보기

module → 최신 JS 모듈 (import/export 가능)

text/javascript / javascript → 일반 JS (기본값, 옛날 방식)

text/babel → Babel로 변환해야 실행되는 JS/JSX (React에서 자주 사용)

module의 최상위 스코프는 undefined

<script type="module">에서 **최상위 스코프의 this는 undefined
(만약 type="text/javascript"였다면 전역 객체인 window가 됨)

0개의 댓글