Javascript Course - The Basics of Object-Oriented Programming

Started by Cikfo, Dec 23, 2022, 01:19 AM

Previous topic - Next topic

Cikfo

JavaScript is a type of client-side scripting language that can be used to build dynamic web pages, automate some tasks, and respond to user actions. It is similar to most scripting languages, but is not strongly typed, meaning it is loosely structured. Some of its features, such as deferred scripts, can reduce loading and display time. But it also raises security concerns.

Unlike conventional OO languages, JavaScript does not differentiate between variables, methods, properties, and prototypes. Instead, it makes use of object literals. However, it does not support some OO features, such as concepts-level scope. To help you understand how objects work in JavaScript, let's examine some of the basics.

An object is a collection of properties and sub-properties. These can be boolean or logical, but are generally defined by their value. For example, an object has a property called 'innerHTML'. This property contains all the text that appears inside an HTML element. Most browsers support this property.

JavaScript has a unique for-index-in loop. It also has a bitwise XOR operator. In addition to these, it has a special property for objects called undefined. When this property is set, the object will have a default value of false.

JavaScript also has a special keyword called var. This is used to declare a local variable. The var keyword is not recommended. It is more convenient to define a global variable, which is accessible to all scripts. Global variables are usually placed in the HEAD section of the code. They are difficult to test and debug, and clash with local scope.

There are two main types of primitives: number and string. Both can be used to perform numeric operations and manipulate strings. Numbers can be expressed as a number or a boolean, and a string can be composed of any numerical value or concatenated with an empty string "". Boolean data types are also primitives, but they can be true or false.

One interesting feature of JavaScript is the ability to add and modify properties at runtime. These can be added by using the new constructor function. Using a constructor is not as intuitive as defining a function, however. After defining a constructor, a property is added to the object, allowing it to be available to all other objects of the same class that are constructed from that object.

The JavaScript library jQuery is a popular cross-browser tool. JQuery supports client-side scripting, allowing developers to add graphical effects and interactive elements to web pages. Although the library can read files on the client's machine, it cannot write them to the server. While a JavaScript developer may be tempted to create a library that can be written and read to the server, this is not possible.

A JavaScript function can be called as an expression, a function argument, or a return statement. You can also assign the function as a value to a variable. Functions can be nested, which can make it more complicated to read.