DEV Community

Gayathri.R
Gayathri.R

Posted on

share my experience of my first day learning of java script and difference between the java and java script.

what is Java script
JavaScript is a programming language used primarily to create interactive and dynamic content on websites. It runs in your web browser and allows web pages to respond to user actions, control multimedia, animate elements, and more.
**

  1. var (old way – avoid if possible)

var name = "Alice";

Function-scoped.

Can be re-declared and updated.

Hoisted (but with undefined value before declaration).

  1. let (modern way)

let age = 25;

Block-scoped (limited to {} it's defined in).

Can be updated, but not re-declared in the same scope.

Not hoisted in the same way as var.

Block-scoped.

Cannot be updated or re-declared.

Must be initialized when declared.

  1. const (for constants)

const PI = 3.14159;

Block-scoped.

Cannot be updated or re-declared.

Must be initialized when declared.
Static, dynamic data type s

Dynamic Typing in JavaScript

JavaScript does not require you to declare a variable's type.

The data type is determined automatically based on the value assigned.

You can reassign a variable to a different type at any time.

Example:

let x = 10; // x is a Number
x = "Hello"; // now x is a String
x = true; // now x is a Boolean

**JavaScript Data Types

JavaScript has a mix of primitive and reference types:

Primitive Types:

Number

String

Boolean

Null

Undefined

Symbol

BigInt

Reference Types:

Object

Array

Function**

**Type Checking in JavaScript

Use the typeof operator to check a variable’s type:

let x = 42;
console.log(typeof x); // "number"

x = "hello";
console.log(typeof x); // "string"****

**Common Issue with Dynamic Types

Because types are determined at runtime, JavaScript can sometimes produce unexpected behavior:

let x = "5" + 2; // "52" → string concatenation
let y = "5" - 2; // 3 → numeric subtraction (JavaScript converts "5" to number)

Compiler vs Interpreter

Feature Compiler Interpreter

Definition Translates entire code to machine code at once Translates code line-by-line
Speed Faster execution (after compilation) Slower (interprets at runtime)
Error Detection Shows all errors after compilation ****Shows errors one by one while running
Output Creates a separate executable file No separate file – runs directly
Execution Compile → Run Just Run (no separate compile step)

Examples

Compiled Languages

C, C++, Rust, Go, Swift, Java (compiled to bytecode for JVM)

// C code example

include

int main() {
printf("Hello, world!\n");
return 0;
}

Compiled with: gcc file.c -o file

Interpreted Languages

Python, JavaScript, Ruby, PHP

Python example
print("Hello, world!")

Run with: python file.py

Mixed Approach

Some languages use both compilation and interpretation:

Java: Compiled to bytecode → interpreted (or JIT compiled) by the JVM

JavaScript: Interpreted, but modern engines (like V8) use JIT compilation for performanc

Top comments (0)