Showing posts with label Variables. Show all posts
Showing posts with label Variables. Show all posts

Saturday, November 2, 2024

JavaScript Basics: Developer Console, Data Types, Variables, and Essential Functions

JavaScript Basics Guide

JavaScript Fundamentals Guide

๐Ÿ“š Table of Contents

1. JavaScript Developer Console

The Developer Console allows you to run JavaScript directly in your browser for testing and debugging.

๐Ÿ“– Learn More

Use it to test code instantly without creating files.

๐Ÿ’ป Code Example

console.log("Hello, World!");

๐Ÿ–ฅ CLI Output

> Hello, World!

2. JavaScript Data Types

Primitive data types are the building blocks of JavaScript.

๐Ÿ“– View Data Types
  • String: "Hello"
  • Number: 42
  • Boolean: true / false
  • Undefined: let x;
  • Null: let y = null;

๐Ÿ’ป Code Example

var text = "Hello";
var num = 10;
var isTrue = true;

๐Ÿ–ฅ CLI Output

> Hello
> 10
> true

3. Variables using var

The var keyword declares variables but has hoisting behavior.

๐Ÿ“– Hoisting Explained

Variables declared with var are moved to the top and initialized as undefined.

๐Ÿ’ป Code Example

console.log(name);
var name = "Bob";

๐Ÿ–ฅ CLI Output

> undefined

4. Common JavaScript Functions

๐Ÿ“– console.log()

Used for debugging.

console.log("Hello!");
๐Ÿ“– alert()

Displays popup messages.

alert("Welcome!");
๐Ÿ“– prompt()

Takes user input.

var user = prompt("Enter name");

๐Ÿ–ฅ CLI Output

> Hello!
> Welcome!
> User Input

๐Ÿงช Live Code Playground

Try JavaScript directly below:

๐Ÿง  Interactive Quiz

1. What is the output of console.log(typeof null)?

2. Which keyword has block scope?

๐Ÿ’ก Key Takeaways

  • Console helps test code quickly
  • Primitive types are core building blocks
  • var has hoisting behavior
  • Functions help debugging and interaction

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts