🎁GET 20% OFF Using Code 👉SCHOOL👈 Until End 2024🎁

History

JavaScript is a popular general-purpose scripting language that follows the ECMAScript standard maintained by the Ecma International and is widely used for web applications. It is released under the open source W3C Software License by web browser vendors and runtime environment vendors.

Brendan Eich created JavaScript as an employee of Netscape in 1995. first released Python as version 0.9.0 in 1991. Ecma Technical Committee 30 (TC39) contribute to the development and maintenance of the ECMAScript specification.

JavaScript runs in a web browser for client-side interactive or automated web applications. Server-side embedded platforms allow JavaScript applications to run outside a web browser.

JavaScript as a scripting language, is commonly used for loading content without refreshing the website, validating form input, tracking users on a website, video games and graphical applications.

Table : Recommended ECMAScript Versions

VersionReleasedSupport EndSecurity End
20222022-06-08N/AN/A
20232023-06-28N/AN/A
20242024-06-28N/AN/A
20252025-06-28N/AN/A

Chapter 1: Getting started with JavaScript

In this chapter, you will learn about the brief history of JavaScript, its syntax, comments and string formatting. You can use your favorite text editor, IDE or use the built-in IDE on OjamboShop.com Course. The built-in IDE can also be used to compile your code.

If you use your own text editor or IDE, you will need to also install a web browser in order for your code to be interpreted. The built-in IDE has syntax highlighting using different colors for the keywords, comments, control-flow statements, variables and other elements.

To use the built-in IDE simple type the code in the IDE and click the compile button to display the results in the output area. Otherwise follow the requirements for the text editor and JavaScript.

Requirements:

  1. Optional text editor for programming recommended
  2. Optional web browser installed and configured

About

Edward Ojambo has been programming in various languages since 1985. He works as a freelance programmer creating custom databases, web, desktop and mobile applications. Private one-on-one tutorials are offered for computer programming, website development, custom applications, Linux, email servers, web servers and search engine optimization.

All content was created for educational purposes and is not affiliated with official JavaScript. The content was extracted from examples that Edward Ojambo uses during work-related activities.

The content is released under Creative Commons BY-SA 4.0, and the list of contributors to each chapter are provided in the credits section at the end of this course. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.

Use the content present in this course at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to OjamboShop.com.

Certificate

CERTIFICATE OF COMPLETIONThis is presented to:Edward OjamboOnline: Learning PYTHONDate: 2024-06-22Edward OjamboAuthorOjamboShop.com

References

Supported versions https://devguide.python.org/versions

Language Reference https://docs.python.org/3/reference

Exceptions https://docs.python.org/3/tutorial/errors.html

Basic Use Of Exceptions

Exceptions can be thrown and caught. Surround code in a try block. If an exception is thrown and its current function scope has no catch block, the exception will “bubble up” the call stack to the calling function until it finds a matching catch block. All finally blocks it encounters along the way will be executed.

Try

Sample Codetry:
	print(x)
except:
	print(“An exception Occured Because X Is Undefined”)
def divide(x, y):
    try:
        result = x // y
        print(“Answer is :”, result)
    except ZeroDivisionError:
        print(“Cannot divide by zero!”)
divide(3, 2)
divide(3, 0)

Finally

Sample Codedef divide(x, y):
    try:
        result = x // y
    except ZeroDivisionError:
        print(“Cannot divide by zero!”)
    else:
        print(“Answer is :”, result)
    finally:
        print(‘Always executed’)
divide(3, 2)
divide(3, 0)
# Type Some Code

Chapter 10: Exceptions

During the execution of a program, it may be required to process special conditions called exceptions. An exception breaks the normal execution flow and executes a specified exception handler.

An exceptional event could occur from an error and the Python will try to find a matching exception block. Python uses try with at least one corresponding catch or finally block. An exception can be thrown or caught.

Table : Exceptions

FunctionDescriptionExample
tryExecutes only if exception triggerstry: print(x) except: print(“Undefined”)
exceptBlock that handles errortry: print(x) except: print(“Undefined”)
elseBlock that is executed when no errortry: print(“Hello”) except: print(“Something went wrong”) else: print(“Nothing went wrong”)
finallyExceutes code regardless of try except block resulttry: print(x) except: print(“Something went wrong”) finally: print(“The ‘try except’ is finished”)

Chapter 9: Modules

Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. The file is called a module and definitions from a module can be imported into other modules or into the main module.

Therefore the main module is a collection of variables that be accessed in a script executed at the top level. The file name is the module name with the suffix .py appended. Within a module, the module’s name as a string is available as the value of the global variable __name__.

Create Module

Sample Codedef greeting(name)
	print(“Hello, ” + name)
personx = {
	“name”: “John”,
	“age”: 24
}
# Save the code snippet above in a file named mymodule.py

Use Module

Sample Codeimport mymodule
mymodule.greeting(“John”)
# Alternative Method To Import
from mymodule import personx
print(personx[“age”])

Python has several built-in modules that can be imported.

The date is Python is not a data type and can be imported from the datetime module.

Date

Sample Codeimport datetime
timestamp = datetime.datetime.now()
print(timestamp)

Date Objects

	
Sample Codethe_date = datetime.datetime(2024, 9, 2)print("Labor Day 2024 is " + str(the_date)) # Cast Datetime To String

The Python Math module extends the list of mathematical functions.

Math

Sample Codeimport math
num1 – math.pi # PI constants
print(num1)
num2 = math.sqrt(9) # Square Root Of A Number
print(num2)
num3 = math.ceil(11.4) # Rounds A Number Up To Nearest Integer
print(num3)
num4 = math.floor(11.6) # Rounds A Number Down To Nearest Integer
print(num4)

JSON or JavaScript Object Notation is a text format that is a syntax for storing and exchanging data. The Python JSON module allows JSON data to be converted into a dictionary or vice versa.

JSON

Sample Codejson_text = ‘{“name:”John”, “age”:24}’
json_dict = json.loads(json_text) # Parse JSON Text
print(json.dict[“name”])
print(json.dict[“age”])
person_dict = {
	“name”: “John”,
	“age”: 24,
	“retired”: False
}
person_json = json.dumps(person) # Convert Into Json
print(person_json)
# Type Some Code

Class Declaration

An object is created by an executed constructor function of the class. The class defines how objects behave, providing initial values as member variables and implementations of behavior via member functions. Use public and private modifiers to define if functions can be used outside the object.

Class

Sample Codeclass SimpleClass:
	name = “John”
s1 = SimpleClass()
print(s1.name)
class Person:
	def __init__(self, name, age):
		self.name = name
		self.age = age
p1 = Person(“John”, 24)
print(p1.name)
print(p1.age)
class Greeting:
	def __init__(self, name, age):
		self.name = name
		self.age = age
	def greet(self):
		print(“Hello, my name is ” + self.name)
g1 = Greeting(“John, 24)
g1.greet()
g1.age = 34
print(g1.age)
del g1.age
del g1

Table : Common Functions To Manipulate Objects

FunctionDescriptionExample
delDelete object propertiesdel obj
selfParameter to reference the current instancedef myfunction(self):
__str__()Function returned when class is represented as string
__init__()Function automatically called when class is used to create new object
# Type Some Code