JavaScript Basics: Difference between revisions
m automatic correction by IA Tag: Reverted |
m automatic correction by IA Tag: Reverted |
||
| Line 10: | Line 10: | ||
=== Variables === | === Variables === | ||
Variables<ref>{{Citation |title=Variable (computer science) |date=2022-08-19 |url=https://en.wikipedia.org/w/index.php?title=Variable_(computer_science)&oldid=1105315140 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> are data stored as a value in a named space. Variables can be used as a mathematical constant,<ref>{{Citation |title=Constant (mathematics) |date=2022-06-02 |url=https://en.wikipedia.org/w/index.php?title=Constant_(mathematics)&oldid=1091159181 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> to use in math commands to generate a user output,<ref name=":0">{{Citation |title=Input/output |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Input/output&oldid=1107158004 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> such as e,<ref>{{Citation |title=e (mathematical constant) |date=2022-08-26 |url=https://en.wikipedia.org/w/index.php?title=E_(mathematical_constant)&oldid=1106854025 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",<ref>{{Citation |title=const (computer programming) |date=2022-08-20 |url=https://en.wikipedia.org/w/index.php?title=Const_(computer_programming)&oldid=1105407141 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> and add the [[JavaScript syntax#Declaration and assignment|assignment declaration]]. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way | Variables<ref>{{Citation |title=Variable (computer science) |date=2022-08-19 |url=https://en.wikipedia.org/w/index.php?title=Variable_(computer_science)&oldid=1105315140 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> are data stored as a value in a named space. Variables can be used as a mathematical constant,<ref>{{Citation |title=Constant (mathematics) |date=2022-06-02 |url=https://en.wikipedia.org/w/index.php?title=Constant_(mathematics)&oldid=1091159181 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> to use in math commands to generate a user output,<ref name=":0">{{Citation |title=Input/output |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Input/output&oldid=1107158004 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> such as e,<ref>{{Citation |title=e (mathematical constant) |date=2022-08-26 |url=https://en.wikipedia.org/w/index.php?title=E_(mathematical_constant)&oldid=1106854025 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",<ref>{{Citation |title=const (computer programming) |date=2022-08-20 |url=https://en.wikipedia.org/w/index.php?title=Const_(computer_programming)&oldid=1105407141 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> and add the [[JavaScript syntax#Declaration and assignment|assignment declaration]]. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way and can be changed accordingly depending on user input. Variables can also hold strings,<ref>{{Citation |title=String (computer science) |date=2022-08-01 |url=https://en.wikipedia.org/w/index.php?title=String_(computer_science)&oldid=1101756832 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which are useful for input such as authorization<ref>{{Citation |title=Authorization |date=2022-08-18 |url=https://en.wikipedia.org/w/index.php?title=Authorization&oldid=1105166484 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or for a search engine.<ref>{{Citation |title=Search engine |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Search_engine&oldid=1107150189 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> Variables can also be undefined<ref>{{Citation |title=Undefined value |date=2021-12-09 |url=https://en.wikipedia.org/w/index.php?title=Undefined_value&oldid=1059485044 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or null.<ref>{{Citation |title=Null character |date=2022-08-10 |url=https://en.wikipedia.org/w/index.php?title=Null_character&oldid=1103680343 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> | ||
=== Functions === | === Functions === | ||
| Line 16: | Line 16: | ||
=== Event Keywords === | === Event Keywords === | ||
[[Event (computing)|Events]] are triggers usually initiated by user input,<ref name=":0" /> which | [[Event (computing)|Events]] are triggers usually initiated by user input,<ref name=":0" /> which allows certain blocks of code to execute. Here's a [[HTML attribute#Event attributes|complete list]]. | ||
=== WebSockets and User Connections === | === WebSockets and User Connections === | ||
Revision as of 14:31, 27 August 2026
JavaScript Basics
Variables
Variables[1] are data stored as a value in a named space. Variables can be used as a mathematical constant,[2] to use in math commands to generate a user output,[3] such as e,[4] which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",[5] and add the assignment declaration. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way and can be changed accordingly depending on user input. Variables can also hold strings,[6] which are useful for input such as authorization[7] or for a search engine.[8] Variables can also be undefined[9] or null.[10]
Functions
Functions[11] are keywords used in object-oriented programming. These are used to run code multiple times, for example, a login button. They can set up the procedure and insert it inside of a function named loginProcedure. Using the Document Object Model, they can have the function execute when an HTML element is clicked.
Event Keywords
Events are triggers usually initiated by user input,[3] which allows certain blocks of code to execute. Here's a complete list.
WebSockets and User Connections
User connections include social networking,[12] messaging between users,[13] or playing an online game.[14] WebSocket[15] is a protocol used for seamless and fast communication listening on a port.[16] Encoded messages are sent over this line, usually in a JSON format.[17] WebSocket is supported by Google Chrome, Firefox, Safari, Microsoft Edge, Internet Explorer, and Opera. This server can be utilized with a variable. Declare a variable and set the value to "new WebSocket()". Inside of the parentheses put the URL (Uniform Resource Locator) of your WebSocket connection. Create custom functions for this to create a chat application or another idea.
Recap
View the references for more info on this topic. Event keywords, WebSockets, Functions, and Variables were all listed on this page.
// Variables
var variable = 1;
const constant = 2;
// Better to use let keyword
let username = user;
// Functions
function myFunction() {
console.log("Hello World!")
}
// Execute this function
myFunction()
// WebSockets
let socket = new WebSocket("server-url")
/* Add your custom WebSocket
functionality here! */
View the references for more info.
References
- ↑ "Variable (computer science)", Wikipedia, 2022-08-19, retrieved 2022-08-29
- ↑ "Constant (mathematics)", Wikipedia, 2022-06-02, retrieved 2022-08-29
- ↑ 3.0 3.1 "Input/output", Wikipedia, 2022-08-28, retrieved 2022-08-29
- ↑ "e (mathematical constant)", Wikipedia, 2022-08-26, retrieved 2022-08-29
- ↑ "const (computer programming)", Wikipedia, 2022-08-20, retrieved 2022-08-29
- ↑ "String (computer science)", Wikipedia, 2022-08-01, retrieved 2022-08-29
- ↑ "Authorization", Wikipedia, 2022-08-18, retrieved 2022-08-29
- ↑ "Search engine", Wikipedia, 2022-08-28, retrieved 2022-08-29
- ↑ "Undefined value", Wikipedia, 2021-12-09, retrieved 2022-08-29
- ↑ "Null character", Wikipedia, 2022-08-10, retrieved 2022-08-29
- ↑ "Function object", Wikipedia, 2022-04-22, retrieved 2022-08-29
- ↑ "Social networking service", Wikipedia, 2022-08-22, retrieved 2022-08-29
- ↑ "Message", Wikipedia, 2022-07-26, retrieved 2022-08-29
- ↑ "Multiplayer video game", Wikipedia, 2022-08-12, retrieved 2022-08-29
- ↑ "WebSocket", Wikipedia, 2022-08-06, retrieved 2022-08-29
- ↑ "Port (computer networking)", Wikipedia, 2022-08-04, retrieved 2022-08-29
- ↑ "JSON", Wikipedia, 2022-08-25, retrieved 2022-08-29
This article "JavaScript Basics" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:JavaScript Basics. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
