Run a Node.js script and enable strict mode
📦 Node.js-> Command Line
✨ The Prompt Phrase
node --use-strict script.js
💻 Code Preview
📦 All-in-One Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>node --use-strict script.js - Run a Node.js script and enable strict mode - Interactive Tutorial</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&family=Fira+Code:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg-primary: #0a0e27;
--bg-secondary: #151932;
--bg-card: #1e2139;
--accent-purple: #a855f7;
--accent-blue: #3b82f6;
--accent-green: #10b981;
--accent-red: #ef4444;
--accent-yellow: #f59e0b;
--text-primary: #f8fafc;
--text-secondary: #94a3b8;
--gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
--gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
--shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
overflow-x: hidden;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
/* Hero Section */
.hero {
text-align: center;
padding: 100px 20px;
background: var(--gradient-1);
position: relative;
overflow: hidden;
}
.hero::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="2" fill="white" opacity="0.1"/></svg>');
animation: float 20s linear infinite;
}
@keyframes float {
from { transform: translateY(0); }
to { transform: translateY(-100px); }
}
.hero-content {
position: relative;
z-index: 1;
}
.command-display {
display: inline-block;
background: rgba(0, 0, 0, 0.3);
padding: 20px 40px;
border-radius: 15px;
font-family: 'Fira Code', monospace;
font-size: 2rem;
margin: 30px 0;
border: 2px solid rgba(255, 255, 255, 0.2);
animation: pulse 2s ease-in-out infinite;
word-break: break-all;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.hero h1 {
font-size: 3rem;
font-weight: 700;
margin-bottom: 20px;
animation: slideDown 0.8s ease-out;
}
.hero p {
font-size: 1.3rem;
opacity: 0.95;
animation: slideUp 0.8s ease-out;
}
@keyframes slideDown {
from { transform: translateY(-50px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
@keyframes slideUp {
from { transform: translateY(50px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
/* Progress Bar */
.progress-container {
position: sticky;
top: 0;
width: 100%;
height: 5px;
background: var(--bg-secondary);
z-index: 1000;
}
.progress-bar {
height: 100%;
background: var(--gradient-3);
width: 0%;
transition: width 0.3s ease;
}
/* Section Styles */
.section {
margin: 60px 0;
animation: fadeIn 0.8s ease-out;
animation-fill-mode: both;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(30px); }
to { opacity: 1; transform: translateY(0); }
}
.section-title {
font-size: 2.5rem;
margin-bottom: 30px;
background: var(--gradient-3);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
display: inline-block;
}
.card {
background: var(--bg-card);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
box-shadow: var(--shadow);
border: 1px solid rgba(255, 255, 255, 0.05);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 25px 70px rgba(0, 0, 0, 0.4);
}
/* Code Block */
.code-block {
background: #1e1e1e;
border-radius: 15px;
padding: 25px;
margin: 20px 0;
position: relative;
overflow: hidden;
font-family: 'Fira Code', monospace;
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.code-lang {
color: var(--accent-green);
font-weight: 600;
}
.copy-btn {
background: var(--accent-purple);
color: white;
border: none;
padding: 8px 16px;
border-radius: 8px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.3s ease;
}
.copy-btn:hover {
background: var(--accent-blue);
transform: scale(1.05);
}
.copy-btn.copied {
background: var(--accent-green);
}
pre {
margin: 0;
overflow-x: auto;
}
code {
color: #e0e0e0;
font-size: 0.95rem;
line-height: 1.6;
}
.code-comment {
color: #6a9955;
}
.code-keyword {
color: #569cd6;
}
.code-string {
color: #ce9178;
}
.code-error {
color: #f48771;
}
/* Steps */
.steps {
counter-reset: step-counter;
}
.step {
background: var(--bg-secondary);
border-radius: 15px;
padding: 30px;
margin: 20px 0;
position: relative;
padding-left: 80px;
transition: all 0.3s ease;
}
.step:hover {
background: var(--bg-card);
transform: translateX(10px);
}
.step::before {
counter-increment: step-counter;
content: counter(step-counter);
position: absolute;
left: 20px;
top: 50%;
transform: translateY(-50%);
width: 50px;
height: 50px;
background: var(--gradient-1);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
font-weight: 700;
}
.step h3 {
color: var(--accent-blue);
margin-bottom: 10px;
}
/* Interactive Demo */
.demo-container {
background: var(--bg-secondary);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.terminal {
background: #1e1e1e;
border-radius: 15px;
padding: 20px;
font-family: 'Fira Code', monospace;
margin: 20px 0;
}
.terminal-header {
display: flex;
gap: 8px;
margin-bottom: 15px;
}
.terminal-dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.terminal-dot.red { background: #ff5f56; }
.terminal-dot.yellow { background: #ffbd2e; }
.terminal-dot.green { background: #27c93f; }
.terminal-content {
color: #e0e0e0;
}
.terminal-prompt {
color: var(--accent-green);
}
.terminal-command {
color: var(--accent-blue);
}
.demo-button {
background: var(--gradient-1);
color: white;
border: none;
padding: 15px 40px;
border-radius: 50px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 10px;
margin: 10px;
}
.demo-button:hover {
transform: scale(1.05);
box-shadow: 0 10px 30px rgba(168, 85, 247, 0.4);
}
.demo-button.danger {
background: var(--gradient-2);
}
/* Tabs */
.tabs {
display: flex;
gap: 10px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.tab {
padding: 12px 24px;
background: var(--bg-secondary);
border: none;
border-radius: 10px;
color: var(--text-primary);
cursor: pointer;
transition: all 0.3s ease;
font-size: 1rem;
}
.tab:hover {
background: var(--bg-card);
}
.tab.active {
background: var(--gradient-1);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
animation: fadeIn 0.5s ease-out;
}
/* Accordion */
.accordion-header {
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background: var(--bg-secondary);
border-radius: 12px;
margin: 15px 0;
transition: all 0.3s ease;
}
.accordion-header:hover {
background: var(--bg-card);
}
.accordion-icon {
transition: transform 0.3s ease;
font-size: 1.2rem;
}
.accordion-icon.active {
transform: rotate(180deg);
}
.accordion-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
}
.accordion-content.active {
max-height: 2000px;
}
.accordion-body {
padding: 20px;
background: var(--bg-secondary);
border-radius: 12px;
margin-top: 5px;
}
/* Tips */
.tip {
background: rgba(59, 130, 246, 0.1);
border-left: 4px solid var(--accent-blue);
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.tip::before {
content: '💡 ';
font-size: 1.5rem;
}
.warning {
background: rgba(239, 68, 68, 0.1);
border-left: 4px solid #ef4444;
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.warning::before {
content: '⚠️ ';
font-size: 1.5rem;
}
.success {
background: rgba(16, 185, 129, 0.1);
border-left: 4px solid var(--accent-green);
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.success::before {
content: '✅ ';
font-size: 1.5rem;
}
/* Quiz */
.quiz-container {
background: var(--bg-card);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.quiz-question {
margin: 30px 0;
}
.quiz-question h3 {
color: var(--accent-purple);
margin-bottom: 20px;
}
.quiz-options {
display: flex;
flex-direction: column;
gap: 15px;
}
.quiz-option {
background: var(--bg-secondary);
padding: 20px;
border-radius: 12px;
cursor: pointer;
transition: all 0.3s ease;
border: 2px solid transparent;
}
.quiz-option:hover {
border-color: var(--accent-blue);
transform: translateX(10px);
}
.quiz-option.correct {
border-color: var(--accent-green);
background: rgba(16, 185, 129, 0.1);
}
.quiz-option.incorrect {
border-color: #ef4444;
background: rgba(239, 68, 68, 0.1);
}
.quiz-feedback {
margin-top: 15px;
padding: 15px;
border-radius: 10px;
display: none;
}
.quiz-feedback.show {
display: block;
animation: slideIn 0.5s ease-out;
}
@keyframes slideIn {
from { opacity: 0; transform: translateX(-20px); }
to { opacity: 1; transform: translateX(0); }
}
.quiz-feedback.correct {
background: rgba(16, 185, 129, 0.1);
border-left: 4px solid var(--accent-green);
}
.quiz-feedback.incorrect {
background: rgba(239, 68, 68, 0.1);
border-left: 4px solid #ef4444;
}
/* Cheat Sheet */
.cheat-sheet {
background: var(--gradient-1);
border-radius: 20px;
padding: 40px;
margin: 30px 0;
}
.cheat-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-top: 30px;
}
.cheat-item {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 20px;
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.cheat-item h4 {
color: var(--accent-green);
margin-bottom: 10px;
}
.badge {
display: inline-block;
padding: 5px 15px;
background: var(--gradient-2);
border-radius: 20px;
font-size: 0.85rem;
font-weight: 600;
margin: 5px;
}
.highlight {
color: var(--accent-green);
font-weight: 600;
}
.comparison-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
.comparison-table th,
.comparison-table td {
padding: 15px;
text-align: left;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.comparison-table th {
background: var(--bg-secondary);
color: var(--accent-blue);
font-weight: 600;
}
.comparison-table tr:hover {
background: rgba(255, 255, 255, 0.05);
}
/* Footer */
.footer {
text-align: center;
padding: 40px 20px;
background: var(--bg-secondary);
margin-top: 80px;
}
.footer p {
color: var(--text-secondary);
margin: 10px 0;
}
/* Confetti */
.confetti {
position: fixed;
width: 10px;
height: 10px;
z-index: 9999;
}
@keyframes confetti-fall {
to {
transform: translateY(100vh) rotate(360deg);
opacity: 0;
}
}
/* Responsive */
@media (max-width: 768px) {
.hero h1 {
font-size: 2rem;
}
.command-display {
font-size: 1.2rem;
padding: 15px 25px;
}
.hero p {
font-size: 1rem;
}
.section-title {
font-size: 1.8rem;
}
.card {
padding: 25px;
}
.step {
padding-left: 70px;
}
.step::before {
width: 40px;
height: 40px;
font-size: 1.2rem;
}
}
.vs-container {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 20px;
align-items: center;
margin: 30px 0;
}
.vs-badge {
background: var(--gradient-2);
padding: 10px 20px;
border-radius: 50px;
font-weight: 700;
font-size: 1.2rem;
}
</style>
</head>
<body>
<div class="progress-container">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="hero">
<div class="hero-content">
<h1>🔒 Master Strict Mode in Node.js</h1>
<div class="command-display">node --use-strict script.js</div>
<p>Write safer, cleaner JavaScript code with strict mode! 🛡️</p>
</div>
</div>
<div class="container">
<!-- What Is It Section -->
<section class="section" id="what-is-it">
<h2 class="section-title">🤔 What Is It?</h2>
<div class="card">
<p style="font-size: 1.2rem; margin-bottom: 20px;">
<strong>node --use-strict script.js</strong> is like putting on <span class="highlight">safety goggles</span> before entering a lab! 🥽
</p>
<p style="margin-bottom: 20px;">
This command runs your JavaScript file (<code>script.js</code>) in Node.js with <strong>strict mode</strong> enabled from the command line. Strict mode is a special JavaScript feature that catches common coding mistakes and prevents you from using "unsafe" actions.
</p>
<div class="tip">
<strong>Think of it like this:</strong> Regular JavaScript is like driving without a seatbelt - it works, but it's risky. Strict mode is like having seatbelts, airbags, and lane assist all turned on! 🚗💨
</div>
<p style="margin-top: 20px;">
The <code>--use-strict</code> flag tells Node.js to automatically wrap your entire script in strict mode, making your code safer and helping you catch bugs early!
</p>
</div>
</section>
<!-- Why Use It Section -->
<section class="section" id="why-use-it">
<h2 class="section-title">✨ Why Use Strict Mode?</h2>
<div class="card">
<div class="cheat-grid">
<div class="cheat-item">
<h4>🐛 Catch Bugs Early</h4>
<p>Converts silent errors into throw errors so you know when something's wrong!</p>
</div>
<div class="cheat-item">
<h4>🚫 Prevent Bad Practices</h4>
<p>Stops you from using dangerous features that can cause bugs.</p>
</div>
<div class="cheat-item">
<h4>⚡ Better Performance</h4>
<p>JavaScript engines can optimize strict mode code better!</p>
</div>
<div class="cheat-item">
<h4>🔮 Future-Proof Code</h4>
<p>Prepares your code for future JavaScript versions.</p>
</div>
<div class="cheat-item">
<h4>📝 Cleaner Code</h4>
<p>Forces you to write more explicit, readable code.</p>
</div>
<div class="cheat-item">
<h4>🎯 No Accidental Globals</h4>
<p>Prevents creating global variables by accident!</p>
</div>
</div>
</div>
</section>
<!-- How Does It Work Section -->
<section class="section" id="how-it-works">
<h2 class="section-title">⚙️ How Does It Work?</h2>
<div class="card">
<p style="margin-bottom: 30px;">Let's break down the command piece by piece! 🧩</p>
<div class="code-block">
<div class="code-header">
<span class="code-lang">Command Anatomy</span>
<button class="copy-btn" onclick="copyCode(this, 'anatomy-cmd')">📋 Copy</button>
</div>
<pre><code id="anatomy-cmd">node --use-strict script.js
│ │ │
│ │ └─ Your JavaScript file
│ └─ Flag to enable strict mode
└─ Node.js runtime</code></pre>
</div>
<div class="steps">
<div class="step">
<h3>node</h3>
<p>The Node.js runtime that executes your JavaScript code outside the browser.</p>
</div>
<div class="step">
<h3>--use-strict</h3>
<p>A command-line flag that wraps your entire script in strict mode automatically. It's like adding <code>'use strict';</code> at the top of every file!</p>
</div>
<div class="step">
<h3>script.js</h3>
<p>The JavaScript file you want to run. Replace this with your actual filename!</p>
</div>
</div>
<div class="success" style="margin-top: 30px;">
<strong>Pro Tip:</strong> You can also enable strict mode by adding <code>'use strict';</code> at the top of your JavaScript file instead of using the flag!
</div>
</div>
</section>
<!-- Strict Mode vs Normal Mode -->
<section class="section" id="comparison">
<h2 class="section-title">⚔️ Strict Mode vs Normal Mode</h2>
<div class="card">
<p style="margin-bottom: 30px;">See the difference in action! 🎭</p>
<div class="tabs">
<button class="tab active" onclick="switchTab('accidental-globals')">Accidental Globals</button>
<button class="tab" onclick="switchTab('silent-errors')">Silent Errors</button>
<button class="tab" onclick="switchTab('this-keyword')">This Keyword</button>
<button class="tab" onclick="switchTab('reserved-words')">Reserved Words</button>
</div>
<div id="accidental-globals" class="tab-content active">
<h3 style="color: var(--accent-yellow); margin-bottom: 20px;">🌍 Accidental Global Variables</h3>
<div class="vs-container">
<div>
<h4 style="color: var(--accent-red); margin-bottom: 15px;">❌ Normal Mode</h4>
<div class="code-block">
<pre><code><span class="code-comment">// Oops! Forgot 'let' or 'const'</span>
myVariable = <span class="code-string">"Hello"</span>;
console.log(myVariable);
<span class="code-comment">// Works! But creates global variable 😱</span>
<span class="code-comment">// Output: Hello</span></code></pre>
</div>
</div>
<div class="vs-badge">VS</div>
<div>
<h4 style="color: var(--accent-green); margin-bottom: 15px;">✅ Strict Mode</h4>
<div class="code-block">
<pre><code><span class="code-string">'use strict'</span>;
<span class="code-comment">// Forgot 'let' or 'const'</span>
myVariable = <span class="code-string">"Hello"</span>;
<span class="code-comment">// ❌ ReferenceError!</span>
<span class="code-comment">// myVariable is not defined</span></code></pre>
</div>
</div>
</div>
<div class="tip">
<strong>Why this matters:</strong> Accidental globals can cause hard-to-find bugs! Strict mode catches this mistake immediately.
</div>
</div>
<div id="silent-errors" class="tab-content">
<h3 style="color: var(--accent-yellow); margin-bottom: 20px;">🤫 Silent Errors Become Loud</h3>
<div class="vs-container">
<div>
<h4 style="color: var(--accent-red); margin-bottom: 15px;">❌ Normal Mode</h4>
<div class="code-block">
<pre><code><span class="code-keyword">const</span> obj = {};
Object.freeze(obj);
obj.newProp = <span class="code-string">"test"</span>;
<span class="code-comment">// Silently fails! 😶</span>
<span class="code-comment">// No error, but doesn't work</span>
console.log(obj.newProp);
<span class="code-comment">// Output: undefined</span></code></pre>
</div>
</div>
<div class="vs-badge">VS</div>
<div>
<h4 style="color: var(--accent-green); margin-bottom: 15px;">✅ Strict Mode</h4>
<div class="code-block">
<pre><code><span class="code-string">'use strict'</span>;
<span class="code-keyword">const</span> obj = {};
Object.freeze(obj);
obj.newProp = <span class="code-string">"test"</span>;
<span class="code-comment">// ❌ TypeError!</span>
<span class="code-comment">// Cannot add property</span></code></pre>
</div>
</div>
</div>
<div class="tip">
<strong>Why this matters:</strong> Silent failures are debugging nightmares! Strict mode makes errors visible.
</div>
</div>
<div id="this-keyword" class="tab-content">
<h3 style="color: var(--accent-yellow); margin-bottom: 20px;">👉 The 'this' Keyword</h3>
<div class="vs-container">
<div>
<h4 style="color: var(--accent-red); margin-bottom: 15px;">❌ Normal Mode</h4>
<div class="code-block">
<pre><code><span class="code-keyword">function</span> showThis() {
console.log(<span class="code-keyword">this</span>);
}
showThis();
<span class="code-comment">// Output: global object 🌍</span>
<span class="code-comment">// (window in browser)</span></code></pre>
</div>
</div>
<div class="vs-badge">VS</div>
<div>
<h4 style="color: var(--accent-green); margin-bottom: 15px;">✅ Strict Mode</h4>
<div class="code-block">
<pre><code><span class="code-string">'use strict'</span>;
<span class="code-keyword">function</span> showThis() {
console.log(<span class="code-keyword">this</span>);
}
showThis();
<span class="code-comment">// Output: undefined ✨</span>
<span class="code-comment">// More predictable!</span></code></pre>
</div>
</div>
</div>
<div class="tip">
<strong>Why this matters:</strong> Having <code>this</code> be <code>undefined</code> is safer than accidentally referring to the global object!
</div>
</div>
<div id="reserved-words" class="tab-content">
<h3 style="color: var(--accent-yellow); margin-bottom: 20px;">🔤 Reserved Words Protection</h3>
<div class="vs-container">
<div>
<h4 style="color: var(--accent-red); margin-bottom: 15px;">❌ Normal Mode</h4>
<div class="code-block">
<pre><code><span class="code-comment">// Using future reserved words</span>
<span class="code-keyword">var</span> private = <span class="code-string">"data"</span>;
<span class="code-keyword">var</span> interface = <span class="code-string">"UI"</span>;
<span class="code-keyword">var</span> package = <span class="code-string">"box"</span>;
<span class="code-comment">// Works, but dangerous! ⚠️</span></code></pre>
</div>
</div>
<div class="vs-badge">VS</div>
<div>
<h4 style="color: var(--accent-green); margin-bottom: 15px;">✅ Strict Mode</h4>
<div class="code-block">
<pre><code><span class="code-string">'use strict'</span>;
<span class="code-keyword">var</span> private = <span class="code-string">"data"</span>;
<span class="code-comment">// ❌ SyntaxError!</span>
<span class="code-comment">// Unexpected strict mode</span>
<span class="code-comment">// reserved word</span></code></pre>
</div>
</div>
</div>
<div class="tip">
<strong>Why this matters:</strong> Future JavaScript versions might use these words. Strict mode protects your code from breaking!
</div>
</div>
</div>
</section>
<!-- Live Demo Section -->
<section class="section" id="demo">
<h2 class="section-title">🎮 Interactive Demo</h2>
<div class="demo-container">
<h3 style="margin-bottom: 20px;">See Strict Mode in Action!</h3>
<p style="margin-bottom: 30px;">Click the buttons to simulate running code with and without strict mode! 👇</p>
<div style="display: flex; gap: 15px; flex-wrap: wrap; margin-bottom: 30px;">
<button class="demo-button danger" onclick="runNormalMode()">
<span>▶️</span>
<span>Run Normal Mode</span>
</button>
<button class="demo-button" onclick="runStrictMode()">
<span>🔒</span>
<span>Run Strict Mode</span>
</button>
</div>
<div class="terminal" id="demoTerminal" style="display: none;">
<div class="terminal-header">
<div class="terminal-dot red"></div>
<div class="terminal-dot yellow"></div>
<div class="terminal-dot green"></div>
</div>
<div class="terminal-content" id="terminalContent"></div>
</div>
</div>
</section>
<!-- Code Breakdown Section -->
<section class="section" id="code-examples">
<h2 class="section-title">💻 Real-World Examples</h2>
<div class="card">
<h3 style="margin-bottom: 20px;">Different Ways to Enable Strict Mode</h3>
<div style="margin: 30px 0;">
<h4 style="color: var(--accent-blue); margin-bottom: 15px;">Method 1: Command Line Flag (Recommended for Node.js)</h4>
<div class="code-block">
<div class="code-header">
<span class="code-lang">Terminal</span>
<button class="copy-btn" onclick="copyCode(this, 'method1')">📋 Copy</button>
</div>
<pre><code id="method1">node --use-strict script.js</code></pre>
</div>
<p style="margin-top: 10px; color: var(--text-secondary);">✅ Applies strict mode to the entire file automatically</p>
</div>
<div style="margin: 30px 0;">
<h4 style="color: var(--accent-blue); margin-bottom: 15px;">Method 2: At the Top of Your File</h4>
<div class="code-block">
<div class="code-header">
<span class="code-lang">script.js</span>
<button class="copy-btn" onclick="copyCode(this, 'method2')">📋 Copy</button>
</div>
<pre><code id="method2"><span class="code-string">'use strict'</span>;
<span class="code-comment">// All code below runs in strict mode</span>
<span class="code-keyword">let</span> name = <span class="code-string">"Alice"</span>;
console.log(name);</code></pre>
</div>
<p style="margin-top: 10px; color: var(--text-secondary);">✅ Most common method, works everywhere</p>
</div>
<div style="margin: 30px 0;">
<h4 style="color: var(--accent-blue); margin-bottom: 15px;">Method 3: Inside a Function (Function-Level)</h4>
<div class="code-block">
<div class="code-header">
<span class="code-lang">script.js</span>
<button class="copy-btn" onclick="copyCode(this, 'method3')">📋 Copy</button>
</div>
<pre><code id="method3"><span class="code-keyword">function</span> strictFunction() {
<span class="code-string">'use strict'</span>;
<span class="code-comment">// Only this function is strict</span>
<span class="code-keyword">let</span> x = <span class="code-string">"safe"</span>;
}
<span class="code-comment">// Rest of the code is not strict</span>
<span class="code-keyword">function</span> normalFunction() {
y = <span class="code-string">"not safe"</span>; <span class="code-comment">// Creates global</span>
}</code></pre>
</div>
<p style="margin-top: 10px; color: var(--text-secondary);">⚠️ Use sparingly, can be confusing</p>
</div>
<div class="tip" style="margin-top: 30px;">
<strong>Best Practice:</strong> Always use strict mode! Modern JavaScript (ES6 modules) enables it automatically, but it's good practice to be explicit.
</div>
</div>
</section>
<!-- Common Mistakes Section -->
<section class="section" id="mistakes">
<h2 class="section-title">❌ Common Mistakes</h2>
<div class="card">
<div class="accordion">
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>1. Putting 'use strict' in the Wrong Place</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Wrong:</strong> Putting code or comments before 'use strict'
</div>
<div class="code-block" style="margin-top: 15px;">
<pre><code><span class="code-comment">// This is a comment</span>
<span class="code-keyword">let</span> x = <span class="code-number">5</span>;
<span class="code-string">'use strict'</span>; <span class="code-comment">// ❌ Too late!</span>
<span class="code-comment">// Strict mode won't work!</span></code></pre>
</div>
<div class="success" style="margin-top: 15px;">
<strong>Correct:</strong> 'use strict' must be the FIRST statement
</div>
<div class="code-block" style="margin-top: 15px;">
<pre><code><span class="code-string">'use strict'</span>; <span class="code-comment">// ✅ First thing!</span>
<span class="code-comment">// Now all code is strict</span>
<span class="code-keyword">let</span> x = <span class="code-number">5</span>;</code></pre>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>2. Mixing Strict and Non-Strict Code</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>The Problem:</strong> Having some files strict and others not can cause confusion!
</div>
<p style="margin-top: 15px;"><strong>Solution:</strong> Be consistent! Either use strict mode everywhere or nowhere. Best practice: use it everywhere!</p>
<div class="tip" style="margin-top: 15px;">
<strong>Pro Tip:</strong> If you're using ES6 modules (<code>import/export</code>), strict mode is automatically enabled! 🎉
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>3. Forgetting to Declare Variables</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Common Error:</strong> Assigning to undeclared variables
</div>
<div class="code-block" style="margin-top: 15px;">
<pre><code><span class="code-string">'use strict'</span>;
<span class="code-comment">// ❌ This will throw an error</span>
myVar = <span class="code-string">"Hello"</span>;
<span class="code-comment">// ✅ Always declare variables</span>
<span class="code-keyword">let</span> myVar = <span class="code-string">"Hello"</span>;
<span class="code-keyword">const</span> myConst = <span class="code-string">"World"</span>;</code></pre>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>4. Deleting Variables or Functions</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Not Allowed in Strict Mode:</strong> You can't delete variables, functions, or function arguments!
</div>
<div class="code-block" style="margin-top: 15px;">
<pre><code><span class="code-string">'use strict'</span>;
<span class="code-keyword">let</span> x = <span class="code-number">5</span>;
<span class="code-keyword">delete</span> x; <span class="code-comment">// ❌ SyntaxError!</span>
<span class="code-keyword">function</span> myFunc() {}
<span class="code-keyword">delete</span> myFunc; <span class="code-comment">// ❌ SyntaxError!</span></code></pre>
</div>
<p style="margin-top: 15px;"><strong>Why?</strong> Deleting variables is confusing and error-prone. Strict mode protects you!</p>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header" onclick="toggleAccordion(this)">
<span><strong>5. Duplicate Parameter Names</strong></span>
<span class="accordion-icon">▼</span>
</div>
<div class="accordion-content">
<div class="accordion-body">
<div class="warning">
<strong>Not Allowed:</strong> Functions can't have duplicate parameter names
</div>
<div class="code-block" style="margin-top: 15px;">
<pre><code><span class="code-string">'use strict'</span>;
<span class="code-comment">// ❌ SyntaxError!</span>
<span class="code-keyword">function</span> sum(a, b, a) {
<span class="code-keyword">return</span> a + b + a;
}
<span class="code-comment">// ✅ Use different names</span>
<span class="code-keyword">function</span> sum(a, b, c) {
<span class="code-keyword">return</span> a + b + c;
}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- What Strict Mode Prevents -->
<section class="section" id="prevents">
<h2 class="section-title">🚫 What Strict Mode Prevents</h2>
<div class="card">
<table class="comparison-table">
<thead>
<tr>
<th>Action</th>
<th>Normal Mode</th>
<th>Strict Mode</th>
</tr>
</thead>
<tbody>
<tr>
<td>Undeclared variables</td>
<td>✅ Creates global</td>
<td>❌ ReferenceError</td>
</tr>
<tr>
<td>Deleting variables</td>
<td>⚠️ Silently fails</td>
<td>❌ SyntaxError</td>
</tr>
<tr>
<td>Duplicate parameters</td>
<td>✅ Allowed</td>
<td>❌ SyntaxError</td>
</tr>
<tr>
<td>Octal numbers (0123)</td>
<td>✅ Allowed</td>
<td>❌ SyntaxError</td>
</tr>
<tr>
<td>Writing to read-only properties</td>
<td>⚠️ Silently fails</td>
<td>❌ TypeError</td>
</tr>
<tr>
<td>Using 'with' statement</td>
<td>✅ Allowed</td>
<td>❌ SyntaxError</td>
</tr>
<tr>
<td>eval creates variables</td>
<td>✅ In outer scope</td>
<td>❌ Only in eval scope</td>
</tr>
<tr>
<td>'this' in functions</td>
<td>Global object</td>
<td>undefined</td>
</tr>
</tbody>
</table>
</div>
</section>
<!-- Pro Tips Section -->
<section class="section" id="pro-tips">
<h2 class="section-title">🚀 Pro Tips</h2>
<div class="card">
<div class="cheat-grid">
<div class="cheat-item">
<h4>🎯 Always Use It</h4>
<p>Make strict mode your default! Add it to every file or use the <code>--use-strict</code> flag.</p>
</div>
<div class="cheat-item">
<h4>📦 ES6 Modules</h4>
<p>If you're using <code>import/export</code>, strict mode is automatic! No need to add it.</p>
</div>
<div class="cheat-item">
<h4>🔧 Linters Love It</h4>
<p>Tools like ESLint work better with strict mode. They catch even more errors!</p>
</div>
<div class="cheat-item">
<h4>⚡ Better Performance</h4>
<p>JavaScript engines can optimize strict mode code more aggressively!</p>
</div>
<div class="cheat-item">
<h4>🎓 Learn Good Habits</h4>
<p>Strict mode teaches you to write better JavaScript from the start!</p>
</div>
<div class="cheat-item">
<h4>🔮 Future-Ready</h4>
<p>New JavaScript features often require strict mode. Stay ahead!</p>
</div>
</div>
<div class="tip" style="margin-top: 30px;">
<strong>🎓 Advanced Tip:</strong> In modern JavaScript projects, use a bundler like Webpack or Vite. They automatically enable strict mode for all modules!
</div>
<div class="success" style="margin-top: 20px;">
<strong>💡 Quick Setup:</strong> Add <code>"type": "module"</code> to your package.json to use ES6 modules (which have strict mode by default)!
</div>
</div>
</section>
<!-- Quiz Section -->
<section class="section" id="quiz">
<h2 class="section-title">🎯 Knowledge Check Quiz</h2>
<div class="quiz-container">
<p style="margin-bottom: 30px;">Test your strict mode mastery! Click on the correct answer. 🧠</p>
<div class="quiz-question">
<h3>Question 1: What does the --use-strict flag do?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">
A) Makes your code run faster
</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 1)">
B) Enables strict mode for the entire script
</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">
C) Compiles JavaScript to machine code
</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 1)">
D) Minifies your code
</div>
</div>
<div class="quiz-feedback" id="feedback1"></div>
</div>
<div class="quiz-question">
<h3>Question 2: What happens if you assign to an undeclared variable in strict mode?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 2)">
A) It creates a global variable
</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 2)">
B) It silently fails
</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 2)">
C) It throws a ReferenceError
</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 2)">
D) It creates a local variable
</div>
</div>
<div class="quiz-feedback" id="feedback2"></div>
</div>
<div class="quiz-question">
<h3>Question 3: Where should 'use strict' be placed in a file?</h3>
<div class="quiz-options">
<div class="quiz-option" onclick="checkAnswer(this, false, 3)">
A) Anywhere in the file
</div>
<div class="quiz-option" onclick="checkAnswer(this, true, 3)">
B) As the first statement
</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 3)">
C) After all variable declarations
</div>
<div class="quiz-option" onclick="checkAnswer(this, false, 3)">
D) At the end of the file
</div>
</div>
<div class="quiz-feedback" id="feedback3"></div>
</div>
<div id="quizScore" style="margin-top: 30px; padding: 20px; background: var(--bg-secondary); border-radius: 12px; display: none;">
<h3 style="color: var(--accent-green);">🎉 Quiz Complete!</h3>
<p id="scoreText" style="font-size: 1.2rem; margin-top: 10px;"></p>
</div>
</div>
</section>
<!-- Cheat Sheet Section -->
<section class="section" id="cheat-sheet">
<h2 class="section-title">📚 Quick Reference Cheat Sheet</h2>
<div class="cheat-sheet">
<h3 style="margin-bottom: 20px;">Save this for later! 🔖</h3>
<div class="cheat-grid">
<div class="cheat-item">
<h4>🎯 Enable Strict Mode</h4>
<p><code>node --use-strict file.js</code></p>
<p><code>'use strict';</code> (in file)</p>
</div>
<div class="cheat-item">
<h4>✅ Benefits</h4>
<p>• Catches bugs early</p>
<p>• Prevents bad practices</p>
<p>• Better performance</p>
</div>
<div class="cheat-item">
<h4>🚫 Prevents</h4>
<p>• Undeclared variables</p>
<p>• Silent errors</p>
<p>• Duplicate parameters</p>
</div>
<div class="cheat-item">
<h4>⚠️ Common Errors</h4>
<p>• ReferenceError</p>
<p>• TypeError</p>
<p>• SyntaxError</p>
</div>
<div class="cheat-item">
<h4>📦 Auto-Enabled In</h4>
<p>• ES6 modules</p>
<p>• Classes</p>
<p>• Async functions</p>
</div>
<div class="cheat-item">
<h4>🎓 Best Practices</h4>
<p>• Always use it</p>
<p>• Put it first</p>
<p>• Be consistent</p>
</div>
</div>
<div style="margin-top: 30px; padding: 20px; background: rgba(255,255,255,0.1); border-radius: 12px;">
<h4 style="color: var(--accent-green); margin-bottom: 15px;">🎯 Quick Command Reference</h4>
<p>1️⃣ Basic usage: <code>node --use-strict script.js</code></p>
<p>2️⃣ With arguments: <code>node --use-strict script.js arg1 arg2</code></p>
<p>3️⃣ Alternative: Add <code>'use strict';</code> at top of file</p>
<p>4️⃣ ES6 modules: Strict mode is automatic! 🎉</p>
</div>
</div>
</section>
<!-- Summary Section -->
<section class="section" id="summary">
<h2 class="section-title">🎓 What You've Learned</h2>
<div class="card">
<h3 style="margin-bottom: 20px;">Congratulations! You're now a strict mode expert! 🏆</h3>
<div style="display: grid; gap: 20px;">
<div style="display: flex; align-items: start; gap: 15px;">
<span style="font-size: 2rem;">✅</span>
<div>
<strong>What strict mode is</strong> - A safer way to write JavaScript that catches errors early
</div>
</div>
<div style="display: flex; align-items: start; gap: 15px;">
<span style="font-size: 2rem;">✅</span>
<div>
<strong>How to enable it</strong> - Using <code>--use-strict</code> flag or <code>'use strict';</code> in your code
</div>
</div>
<div style="display: flex; align-items: start; gap: 15px;">
<span style="font-size: 2rem;">✅</span>
<div>
<strong>Why it's important</strong> - Prevents bugs, improves performance, and teaches good habits
</div>
</div>
<div style="display: flex; align-items: start; gap: 15px;">
<span style="font-size: 2rem;">✅</span>
<div>
<strong>Common mistakes</strong> - What to avoid and how to write safer code
</div>
</div>
<div style="display: flex; align-items: start; gap: 15px;">
<span style="font-size: 2rem;">✅</span>
<div>
<strong>Best practices</strong> - Always use strict mode in your projects!
</div>
</div>
</div>
<div style="margin-top: 40px; padding: 30px; background: var(--gradient-1); border-radius: 15px; text-align: center;">
<h3 style="margin-bottom: 15px;">🚀 Ready to Write Safer Code?</h3>
<p style="font-size: 1.1rem;">You now have all the knowledge to use strict mode like a pro!</p>
<div style="margin-top: 20px;">
<span class="badge">🔒 Strict Mode Master</span>
<span class="badge">🛡️ Code Safety Expert</span>
<span class="badge">⚡ JavaScript Pro</span>
</div>
</div>
</div>
</section>
</div>
<div class="footer">
<h3 style="margin-bottom: 15px;">✨ Tutorial Complete! ✨</h3>
<p>Generated by <strong>AI Prompt Dictionary</strong> 🤖</p>
<p style="margin-top: 10px;">Made with ❤️ and lots of ☕</p>
<p style="margin-top: 20px; color: var(--text-secondary); font-size: 0.9rem;">
© 2026 | Keep learning, keep building! 🚀
</p>
</div>
<script>
// Progress Bar
window.addEventListener('scroll', () => {
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
Live Preview