0% found this document useful (0 votes)
2 views

JavaScript_ Object Orientation, Syntax, Primitives

JavaScript is a prototype-based object-oriented programming language that combines OOP features with a C-like syntax, supporting seven immutable primitive data types. It provides a variety of operators and expressions for performing operations, while output can be managed through the DOM, alerts, or the console, and input is typically handled via prompt dialogs. These characteristics make JavaScript a versatile language for web development.

Uploaded by

divyaammua90
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 views

JavaScript_ Object Orientation, Syntax, Primitives

JavaScript is a prototype-based object-oriented programming language that combines OOP features with a C-like syntax, supporting seven immutable primitive data types. It provides a variety of operators and expressions for performing operations, while output can be managed through the DOM, alerts, or the console, and input is typically handled via prompt dialogs. These characteristics make JavaScript a versatile language for web development.

Uploaded by

divyaammua90
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
You are on page 1/ 3

JavaScript: Object Orientation, Syntax, Primitives, Operations, and I/O

Object Orientation and JavaScript


JavaScript supports object-oriented programming (OOP), but it is prototype-based rather than
strictly class-based like Java or C++. In JavaScript:
Objects are collections of properties (key-value pairs) that can contain data and functions
(methods).
Constructors serve as templates for creating objects; they define the "shape" of objects
and their methods.
Prototypes allow objects to inherit properties and methods from other objects, enabling
inheritance. When a method is defined on a constructor's prototype, all objects created from
that constructor share the method.
The prototype chain is JavaScript’s mechanism for inheritance, allowing objects to inherit
features from other objects [1] [2] .
Example of a constructor and prototype:

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

General Syntactic Characteristics


JavaScript syntax is similar to C and Java:
Case-sensitive.
Statements end with semicolons (optional but recommended).
Curly braces {} define code blocks.
Variable and function names use letters, digits, underscores, and dollar signs.
Uses familiar operators for arithmetic, comparison, and logic [3] .
Example:
let total = 5 + 3;
if (total > 5) {
console.log("Total is greater than 5");
}

Primitives, Operations, and Expressions

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] .

Operations and Expressions


Operators include arithmetic (+, -, *, /, %), assignment (=, +=, etc.), comparison (==, ===, !=,
>, <), logical (&&, ||, !), string concatenation (+), and more [5] [6] .

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

Screen Output and Keyboard Input


Screen Output
JavaScript can display output in several ways:
HTML Output:
document.getElementById("id").innerHTML = "Hello";

document.write("Hello"); (not recommended for modern web apps)


Dialog Boxes:
alert("Hello"); (popup message)
console.log("Hello"); (outputs to browser console) [7] [8] .

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:

let user = prompt("What is your name?");


alert("Welcome, " + user + "!");

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

You might also like