JavaScript Essentials for Real-World Projects: localStorage, Clipboard API & More

![[JS 강좌] 2강 - 개발 환경 구축하기 (VS Code, Chrome 개발자 도구)](/uploads/editor/JS-%EA%B0%95%EC%A2%8C-2%EA%B0%95-%EA%B0%9C%EB%B0%9C-%ED%99%98%EA%B2%BD-%EA%B5%AC%EC%B6%95%ED%95%98%EA%B8%B0-VS-Code-Chrome-%EA%B0%9C%EB%B0%9C%EC%9E%90-%EB%8F%84%EA%B5%AC-20260706-0dfe9b.webp)
How Is JavaScript Used in Real-World Projects?
So far, you've learned basic JavaScript syntax, DOM manipulation, events, and the Fetch API.
However, in actual projects, there are many more commonly used features.
For example:
Saving login information
Storing dark mode settings
Copy buttons
Image preview functionality
Modal windows
Notification messages
Scroll navigation
Today, we'll build these features one by one.
What Is localStorage?
localStorage is a browser feature that allows storing data on the user's device.
The data remains even after refreshing the page or reopening the browser.
Common uses include:
Auto-login functionality
Dark mode settings
Recent search history
Shopping cart data
These are all examples of how localStorage is commonly used.
Storing Data
localStorage.setItem("username","홍길동");
Data is now stored.
Retrieving Data
let name = localStorage.getItem("username");
console.log(name);
Result:
홍길동
Deleting Specific Data
localStorage.removeItem("username");
This removes only the specified data.
Clearing All Data
localStorage.clear();
All stored data will be deleted.
Clipboard API
You've probably seen websites with a 'copy' button that automatically copies text to your clipboard.
This functionality uses the Clipboard API.
navigator.clipboard.writeText("JavaScript");
The text is now copied to your clipboard.
Copy Confirmation Message
navigator.clipboard.writeText("복사할 내용");
alert("복사되었습니다.");
This gives users clear confirmation that the copy was successful.
Image Preview for File Uploads
This is the feature you see when selecting an image in registration forms or forums - it shows a preview of the selected image before uploading.
HTML:
<input type="file" id="photo">
<img id="preview">
Using FileReader
photo.addEventListener("change",function(e){
let file = e.target.files[0];
let reader = new FileReader();
reader.onload = function(){
preview.src = reader.result;
};
reader.readAsDataURL(file);
});
When you select an image, it appears immediately on screen.
What Is a Modal?
A modal is a small window that appears on top of the main content.
Common uses include:
User registration
Delete confirmation prompts
Notice boards
Image zoom functionality
These are all common implementations of modals.
Opening a Modal
modal.style.display = "block";
Closing a Modal
modal.style.display = "none";
Modern implementations often use CSS classes instead:
modal.classList.add("show");
What Is a Toast Message?
A toast message is a notification that briefly appears at the bottom of the screen and then disappears.
Common examples include:
"Saved successfully."
"Copied to clipboard."
"Deleted successfully."
These are used for brief user notifications.
Creating a Toast Message
toast.textContent =
"저장되었습니다."
;
toast.classList.add("show");
Hiding After a Set Time
setTimeout(function(){
toast.classList.remove("show");
},2000);
The message disappears after 2 seconds.
confirm()
You can also display a confirmation dialog before deleting items.
if(confirm("삭제하시겠습니까?")){
console.log("삭제");
}
This is a commonly used feature in real-world applications.
prompt()
You can also collect input from users using prompt().
let name = prompt("이름을 입력하세요.");
console.log(name);
This is often used for learning purposes.
Navigating to the Top of Page
window.scrollTo({
top:0,
behavior:"smooth"
});
This is commonly used for 'back to top' buttons.
Getting Current URL
console.log(location.href);
This retrieves the current page URL.
Navigating to Another Page
location.href="index.html";
You can navigate between pages using JavaScript alone.
Opening a New Window
window.open("https://example.com");
This opens a new browser window or tab.
Checking Browser Dimensions
console.log(window.innerWidth);
console.log(window.innerHeight);
This is frequently used in responsive web design.
Reading URL Parameters
For example:
view.html?id=10
Would require:
let params =
new URLSearchParams(location.search);
console.log(params.get("id"));
Result:
10
This is commonly used in view pages for forums or articles.
How These Features Are Used in Practice
The features covered today are used on almost every website.
For example:
Saving login info (localStorage)
Share buttons (Clipboard API)
Profile image uploads (FileReader)
Delete confirmation prompts (Modal)
Save success messages (Toast)
Article detail pages (URL parameters)
'Back to top' buttons (Scrolling)
You can implement these features in your projects.
Key Takeaways from This Lesson
Today, you learned essential JavaScript techniques used in real-world development.
The key points to remember are:
localStorage stores data on the browser.
Clipboard API copies text to clipboard.
FileReader enables image previews.
Modals create popup windows.
Toast messages are brief notifications that disappear after a short time.
URLSearchParams reads parameters from the URL.
These features are used in most web projects.
Closing Thoughts
In this lesson, we built practical JavaScript features that are commonly used in real projects.
While these may seem like small features individually, combining them creates a superior user experience on websites.
Try implementing the examples from this lesson - store data, create copy buttons, build image previews, implement modals and toast notifications. Mastering these techniques will be invaluable for any future project you work on.
In our next lesson, we'll cover debugging techniques, common mistakes in real-world development, and how to use ChatGPT for JavaScript development.
FAQ
What is localStorage?
localStorage is a browser feature that allows storing data on the user's device. The data remains even after refreshing the page or reopening the browser.
How does the Clipboard API work?
The Clipboard API enables copying text to the clipboard with navigator.clipboard.writeText(). It can be combined with confirmation messages for better user experience.
What is a modal in web development?
A modal is a small window that appears on top of the main content, often used for registration forms, delete confirmations, or image zooms.
Korean Source
This article is an English localization of a Korean-language report from BlogScore. Original: [JS 강좌] 14강 - 자주 사용하는 JavaScript 기능 모음 (localStorage, Clipboard, 파일 업로드 미리보기, 모달, 토스트 메시지 등)