tinycodinglm / code /code021.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame Contribute Delete
2.16 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

What are JavaScript best practices?

Assistant

Modern JavaScript (ES6+):

javascript
// Use const by default, let when needed, never var
const API_URL = "https://api.example.com";
let count = 0;

// Use arrow functions for callbacks
items.map(item => item.name);

// Use template literals
const msg = `Hello ${name}`;

// Use destructuring
const { id, name } = user;
const [first, ...rest] = array;

// Use optional chaining
const city = user?.address?.city;

// Use nullish coalescing
const value = input ?? defaultValue;

Common Mistakes:

javascript
// Bad: loose equality
if (x == "0") { }
if (x == null) { }

// Good: strict equality
if (x === "0") { }
if (x === null) { }

Error Handling:

javascript
// Bad
try {
  await fetch(url);
} catch (e) {} // swallows error

// Good
try {
  await fetch(url);
} catch (e) {
  console.error("Fetch failed:", e);
  throw e;
}

Async/Await:

javascript
// Bad: callback hell
getData(function(a) {
  getMore(a, function(b) {
    getMore(b, function(c) { });
  });
});

// Good: async/await
async function getData() {
  const a = await getData();
  const b = await getMore(a);
  const c = await getMore(b);
  return c;
}

Performance:

  • Use requestAnimationFrame for animations
  • Debounce/throttle event handlers
  • Use Web Workers for heavy computation
  • Lazy load images and components
  • Avoid memory leaks (clean up event listeners)