Greetings! Today, we're about to start an exciting journey into the world of JavaScript. We'll focus on JavaScript fundamentals - printing, comments, data types, and expressions. Imagine you can make a website play a game with its visitors or react to their actions like a fellow human. That's what JavaScript does! Ready to dive in? Let's start.
JavaScript brings static web pages to life by making them interactive! Every language has syntax — rules about how sentences (or in our case, statements) should be written. JavaScript is no exception. Let's have a quick look:
In the above example, we're giving a shoutout to the world: "Hello, World!". You'll often see semicolons (;) at the end of statements in JavaScript. In JavaScript this is optional as it has a feature called Automatic Semicolon Insertion (ASI) that can add them for you. Many developers include them explicitly for clarity and consistency.
A great start, isn't it? Let's keep going.
Coding isn’t just for computers. You also leave notes for fellow humans — future developers or even your future self — known as 'comments'. A comment can either be a one-liner that uses //, or a note stretching across multiple lines within /* and */. These comments explain your code’s purpose, design, and functioning, making reading code much easier.
An essential thing to note is that, unlike JavaScript statements, comments do not need to end with a semi-colon (;). This is because they're not executable code and are ignored by the JavaScript engine.
JavaScript works with many data types, but let's start with three fundamental ones: Numbers, Strings, and Booleans. Try entering the following commands and observe the results:
