[Go to site: main page, start]

0% found this document useful (0 votes)
4 views7 pages

JavaScript Basics Printing Data Types

This document serves as a beginner's guide to JavaScript basics, focusing on printing, comments, and data types. It explains the use of console.log() for output, various data types in JavaScript, and the importance of comments for code clarity. Additionally, it highlights best practices for variable declaration using const and let, while advising against the use of var.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

JavaScript Basics Printing Data Types

This document serves as a beginner's guide to JavaScript basics, focusing on printing, comments, and data types. It explains the use of console.log() for output, various data types in JavaScript, and the importance of comments for code clarity. Additionally, it highlights best practices for variable declaration using const and let, while advising against the use of var.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

📘 JavaScript Basics: Printing

& Data Types


A Beginner's Guide

🖨️ Chapter 1: Printing in JavaScript


What is Printing?
When we say "printing" in programming, we don't mean a physical printer! It
means displaying information on the screen — specifically, in the console (a
special output area for developers).

The Most Common Way: [Link]()


The go-to command for printing anything in JavaScript is:

[Link]("Hello, World!");

This will display: Hello, World!

💡 Why is this important? is used by both beginner and senior


[Link]()

programmers every day to check what's happening in their code — a


process called debugging.

Other Ways to Print


JavaScript offers several other printing methods. You won't use them often, but
it's good to know they exist:
Method What it does
[Link]() Standard output with a new line
[Link]() Prints with a warning color (visible in browsers)
[Link]() Prints data in a neat table format
[Link]() Clears all previous console output
[Link]() Prints without adding a new line at the end

📘 JavaScript Basics: Printing & Data Types 1


⚠️ Note: does not add a new line automatically, so
[Link]()

multiple prints appear on the same line. [Link]() handles this for you
automatically.

Try it yourself!
[Link]("I am learning JavaScript!");
[Link]("This is a warning!");
[Link]({ city: "Jaipur" });

📝 Chapter 2: Comments in Code


Before diving into data types, let's learn about comments — notes you write
inside your code that the computer ignores when running the program.

Single-Line Comment
// This is a single-line comment
[Link]("This runs!"); // This part is also a comment

Multi-Line Comment
/*
This is a multi-line comment.
You can write as many lines as you want here.
The computer will skip all of this.
*/

💡 Shortcut: In most code editors, press Ctrl + / (or Cmd + / on Mac) to


instantly comment out a line.
Why write comments? They help you (and others) understand what your code
is doing. It's a great habit to develop early!

🗂️ Chapter 3: Data Types in JavaScript


What is a Data Type?

📘 JavaScript Basics: Printing & Data Types 2


Think of a data type like a bank form. When you fill out a bank form, some
fields ask for numbers (your account number), some ask for text (your name),
and some ask for a checkmark (yes/no questions). Similarly, JavaScript needs
to know what kind of data it's working with.
JavaScript has 8 main data types:

1. 🔤 String

📘 JavaScript Basics: Printing & Data Types 3


A string is any piece of text. It must be wrapped in quotes (single ' or double
" ).

let myName = "Hitesh";


let website = "[Link]";

2. 🔢 Number
A number can be a whole number or a decimal.

let score = 102;


let price = 3.5;

3. ✅ Boolean
A boolean has only two possible values: true or false . Think of it as a yes/no
answer.

let isLoggedIn = true;


let isHotOutside = false;

Example: "Is 10 bigger than 11?" → false . "Did the user log in?" → true .

4. 🔭 BigInt
Used for extremely large numbers that go beyond what a regular Number can
handle — mostly in scientific or financial calculations.

5. ❓ Undefined vs. Null


These two are often confused by beginners. Here's the key difference:
undefined null

"I exist, but I have no value


Meaning "I am intentionally empty"
yet"
Set by JavaScript automatically You, the programmer
A variable declared but not A temperature reading that returned
Example
assigned nothing from the server

📘 JavaScript Basics: Printing & Data Types 4


🌡️ Analogy: If a weather app asks the server for today's temperature and
gets no response, the value should be null — not 0 , because 0° is a valid
temperature!

6. 📦 Object (Arrays & Dictionaries)


Objects are used to store collections of data. There are two common forms:
Array — a list of items:

let teaTypes = ["lemon tea", "orange tea", "oolong tea"];

Object/Dictionary — data with labels (key-value pairs):

let user = {
firstName: "Hitesh",
lastName: "Choudhary"
};

7. 🔑 Symbol
Used to create unique identifiers — ensuring that a value is one-of-a-kind in
your program.

📦 Chapter 4: Variables — Storing Data in Memory


What is a Variable?
A variable is like a labeled bucket in your computer's memory. You give it a
name, and you can store any value inside it. Later, you can use that name to
access or change the value.

The Three Keywords: var , let , and const


JavaScript has three ways to create a variable:

❌ var — The Old Way (Avoid This)


var score = 102; // Old way — avoid in modern code

📘 JavaScript Basics: Printing & Data Types 5


This still works, but it has some tricky behaviors that can cause bugs in
complex programs.

✅ let — The Modern Way (Use When Value Can Change)


let gameName = "Spider-Man";
gameName = "Batman"; // You can change it later!
[Link](gameName); // Prints: Batman

Use let when you expect the value to change over time.

🔒 const — For Values That Should NOT Change


const username = "[Link]";
username = "hitesh"; // ❌ ERROR! Cannot reassign a const v
ariable.

If you try to change a const variable, JavaScript will throw a TypeError:


"Assignment to constant variable."
💡 Best Practice: Experienced programmers start with by default.
const

They only switch to let if they know the value needs to change. This makes
code more reliable and predictable.

Quick Comparison Table


Keyword Can Change? Modern? Use When...
var ✅ Yes ❌ Old Working with legacy code only
let ✅ Yes ✅ Yes Value needs to change
const ❌ No ✅ Yes Value stays the same (default
choice)

🔁 Chapter 5: Borrowing Values Between Variables


You can assign the value of one variable to another:

let score = 102;


let getScore = score; // getScore now also holds 102

📘 JavaScript Basics: Printing & Data Types 6


[Link](getScore); // Prints: 102

⚠️ Remember: Just storing a value in a variable doesn't display it. You must
use [Link]() to see it on screen. The computer only does what you
explicitly tell it to do.

🧠 Key Takeaways
Use [Link]() to print anything to the screen.
Use comments ( // or /* */ ) to write notes in your code.
JavaScript has 8 data types: String, Number, Boolean, BigInt, Undefined,
Null, Object, and Symbol.
Use const by default; switch to let only when the value needs to change.
Avoid var in modern JavaScript.
null means intentionally empty; undefined means not yet defined.

✏️ Practice Exercises
1. Print your name and age using [Link]() .
2. Create a const variable for your country name and a let variable for your
current city.
3. Create a boolean variable called isStudent and set it to true .
4. Try creating a const variable and then changing its value — observe the
error!
5. Create an array of your 3 favorite foods and print it using [Link]() .

📘 JavaScript Basics: Printing & Data Types 7

You might also like