JavaScript_ Object Orientation, Syntax, Primitives
JavaScript_ Object Orientation, Syntax, Primitives
function Person(name) {
this.name = name;
}
Person.prototype.introduce = function() {
console.log("Hi, I'm " + this.name);
};
let alice = new Person("Alice");
alice.introduce(); // Hi, I'm Alice
Primitives
JavaScript has seven primitive data types, which are not objects and have no methods or
properties:
string
number
bigint
boolean
undefined
symbol
null
Primitives are immutable, though variables holding them can be reassigned [4] .
Expressions combine values, variables, and operators to produce a result. They can be
simple (let x = 5;) or complex (let y = (x * 2) + 7;).
Example:
let a = 10;
let b = 3;
let sum = a + b; // 13
let isEqual = a === b; // false
let isEven = (a % 2 === 0) ? true : false; // true
Keyboard Input
Prompt Dialog:
let name = prompt("Enter your name:"); (shows a dialog box for user input)
Confirm Dialog:
let result = confirm("Are you sure?"); (shows OK/Cancel, returns boolean) [8] .
Example:
Summary:
JavaScript blends object-oriented features (via prototypes and constructors) with a C-like
syntax, supports several immutable primitive types, and offers a rich set of operators and
expressions. Output is typically managed via the DOM, alerts, or the console, while basic input
uses prompt dialogs. These features make JavaScript a flexible and powerful language for web
development.
⁂
1. https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Advanced_JavaScript_o
bjects/Object-oriented_programming
2. https://www.freecodecamp.org/news/object-oriented-programming-javascript/
3. https://study.com/academy/lesson/javascript-syntax-overview-examples.html
4. https://developer.mozilla.org/en-US/docs/Glossary/Primitive
5. https://masteringbackend.com/hubs/javascript-essentials/operators-and-expressions
6. https://www.w3schools.com/js/js_operators.asp
7. https://www.w3schools.com/js/js_output.asp
8. https://www.startertutorials.com/ajwt/input-output.html