. let total = 0; total = total + 1. Functions, arrays, objects, then DOM: document.querySelector('button').addEventListener('click', …). Trap: ‘Java and JavaScript are the same’. Trap: putting a huge script in without defer so the page waits."}}]}]}

Introduction to JavaScript — JS Technical Interview Questions & Answers

What JavaScript is, and why every browser runs it.

Introduction to JavaScript

  • What JavaScript is, and why every browser runs it.
  • JavaScript is the language that runs in the browser to make pages interactive: clicks, validation, fetch from an API. It is not Java. Node.js also runs JavaScript on the server, but this chapter is the browser first.
  • Smallest program: in the console, or a <script>console.log('Hello JS')</script>. let total = 0; total = total + 1. Functions, arrays, objects, then DOM: document.querySelector('button').addEventListener('click', …).
  • Trap: ‘Java and JavaScript are the same’. Trap: putting a huge script in <head> without defer so the page waits.

Technical Interview Tip: Not Java. console.log, then a button click.

Code Examples for Introduction to JavaScript

Introduction to JavaScript — working example

// JavaScript runs in browsers and Node.js
console.log("Hello, JavaScript!");
console.log(typeof "hi", typeof 42, typeof true);

function add(a, b) {
  return a + b;
}
console.log(add(2, 3));

Introduction to JavaScript — jS is a dynamic language for interactive web pages and servers; start with console + small functions.

How to Explain Introduction to JavaScript to an Interviewer

What is JavaScript?

Language in the browser (and Node) Not Java

First example?

console.log('Hello JS')