Introduction to JavaScript Basics

Jul 17, 2024

JavaScript Lecture 1 Notes

Objective

  • Start a series on JavaScript: from beginner to advanced level
  • Prerequisite: No programming experience required
  • Focus: Practical examples and projects along with theory

What is JavaScript?

  • A programming language popular for web development
  • Used to give instructions to computers and machines
  • Can be run in the browser

How to run JavaScript code?

  1. In the browser console
  2. Using a code editor (VS Code)

VS Code

  • Free, popular, and supports various languages
  • How to download and install
  • How to create an HTML file and link it with a JavaScript file

First JavaScript Program

  • Using console.log to print a message on the console
console.log('Apna College');
  • In the console, the code disappears upon refreshing the browser, but the code in the file remains permanent

Variables

  • Containers for data
  • Can store various types of data (number, string, boolean)

How to declare variables

  • Using let, const, and var keywords
  • let and const are preferable

Primitive Data Types

  • Number: let age = 24;
  • String: let name = 'Tony Stark';
  • Boolean: let isFollow = true;
  • Undefined: let x; // x is undefined
  • Null: let x = null;
  • BigInt: let x = BigInt(123);
  • Symbol: let y = Symbol('hello');

Non-Primitive Data Types

  • Objects: Collection of key-value pairs
  • Arrays and functions are also objects
  • Object example:
const student = {
 fulName: 'Rahul Kumar',
 age: 20,
 cgpa: 8.2,
 isPass: true
};
  • Access: Dot notation and bracket notation

Solving Practice Questions

Practice Question 1

  • Store data of amazonflex.in
const product = {
 title: 'Parker Jotter Standard CT Ball Pen',
 rating: 4,
 offer: 5,
 price: 270
};
console.log(product);

Practice Question 2

  • Store instagram follower data
const profile = {
 userName: 'shraddha_kapoor',
 isFollow: false,
 followers: 2000,
 following: 180
};
console.log(profile);

Notes

  • JavaScript is a dynamically typed language
  • Styling cases: Camel case, Pascal case, Snake case, Kebab case
  • Working on properties and methods of objects

Conclusion

  • Covered basics such as variables, data types, and practice questions
  • Will go into more detail in future lectures

Keep Learning and Keep Coding