0% found this document useful (0 votes)
2 views3 pages

JavaScript Basics and Conventions

JavaScript features variable declarations with var, let, and const, where let and const are preferred for block-scoping. It supports dynamic typing, various data types, and different function types, including arrow functions. Additionally, JavaScript has unique naming conventions, truthy/falsy values, strict equality checks, and concepts like closures and the dynamic nature of the 'this' keyword.

Uploaded by

Obaid Abdullah
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)
2 views3 pages

JavaScript Basics and Conventions

JavaScript features variable declarations with var, let, and const, where let and const are preferred for block-scoping. It supports dynamic typing, various data types, and different function types, including arrow functions. Additionally, JavaScript has unique naming conventions, truthy/falsy values, strict equality checks, and concepts like closures and the dynamic nature of the 'this' keyword.

Uploaded by

Obaid Abdullah
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 (Different from C++/Java)

1. Variable Declaration:

- var: function-scoped (avoid using)

- let: block-scoped (preferred)

- const: block-scoped, cannot be reassigned

2. Data Types:

- Primitive types: string, number, boolean, null, undefined, symbol, bigint

- Dynamic typing: Variables can hold any type and change types

3. Functions:

- Function expressions, arrow functions, anonymous functions are common

- Example: const add = (a, b) => a + b;

4. Objects and Arrays:

- JSON-like syntax for objects: const user = { name: "Alice", age: 25 };

- Arrays: const nums = [1, 2, 3];

5. Loops:

- for...in: iterates over keys in an object

- for...of: iterates over values of iterable objects like arrays

6. DOM Manipulation:

- [Link], querySelector, addEventListener, etc.

7. Naming Conventions (Different from Java/C++):


- camelCase for variables and functions: let myVariable

- PascalCase for classes and constructors: class UserAccount

- Constants often use UPPER_CASE: const MAX_USERS = 100;

- Filenames usually use kebab-case or camelCase (unlike Java's PascalCase)

8. Semicolons:

- Optional in JS but recommended to avoid issues with automatic semicolon insertion

9. Truthy/Falsy:

- Values like 0, "", null, undefined, NaN, false are falsy

- All others are truthy

10. Equality:

- == vs === : Always use === (strict equality)

- != vs !== : Always use !==

11. Scope and Hoisting:

- var declarations are hoisted and scoped to function

- let/const are block-scoped and not hoisted in the same way

12. This keyword:

- Dynamic in JS, based on how a function is called (unlike static binding in Java)

- Arrow functions do not bind their own this

13. Closures:

- Functions can remember variables from their lexical scope


JavaScript is loosely typed, event-driven, and asynchronous-friendly with features like callbacks, promises,

You might also like