JavaScript File

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

A File represents a file from an <input type="file"> or drag-and-drop. It extends Blob with name and lastModified.

JavaScript Syntax

JavaScript
const f = new File(["hello"], "note.txt", { type: "text/plain" });
console.log(f.name);
console.log(f.size);
f.text().then(console.log);
Try it Editor

How It Works

  1. new File. Parts + name.
  2. size/name. Metadata.
  3. text(). Read contents (promise).

Examples

Example 1 — Demo

Core usage.

JavaScript
const f = new File(["hello"], "note.txt", { type: "text/plain" });
console.log(f.name);
console.log(f.size);
f.text().then(console.log);
Try it Editor

How It Works

  1. new File. Parts + name.
  2. size/name. Metadata.
  3. text(). Read contents (promise).

Frequently Asked Questions

A File represents a file from an &lt;input type="file"&gt; or drag-and-drop. It extends Blob with name and lastModified.
See JavaScript File handling for the end-to-end input → read flow.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful