Introduction to JavaScript :
JavaScript, widely employed in web development, is a versatile programming language. It allows dynamic, interactive scripting on the client side within browsers. Serving as a fundamental element in contemporary web development stacks, JavaScript improves user interfaces, supports asynchronous operations, and plays a pivotal role in crafting dynamic and captivating web applications.
JavaScript has consistently been accessible to Salesforce developers. With the introduction of Lightning Components and Lightning Web Components, it has become a crucial language for Salesforce developers. This underscores the significance for every Salesforce developer to acquire proficiency in JavaScript.
JavaScript provide dynamic working to HTML elements and developers can dynamically change the CSS of elements . that all we are going to discuss later in this series .
Display Possibilities of JavaScript :
- Writing into an HTML element, using innerHTML .
- Writing into the HTML output using
document.write()
. - Writing into an alert box, using
window.alert()
. - Writing into the browser console, using
console.log()
.
Example of innerHTML :To access an HTML element in JavaScript you can use innerHTML . here is the example of the same .
you need to define the id for the HTML element so that he can refer it in the JS file . in above example we use inline JS but you can create separate JS file and connect it with your HTML file with <script> tag. you need to provide source to script tag and source is name of your JS file in below image name of JS file is myscripts.js .
Example of document.write() :
document.write() is method that is used to display content . however usage of this method has been less due to its behavior. its usage leads to many unexpected behaviors .
here is example of document.write().
Example of window.alert():
window.alert() is a method of JS which is used to give alert on top of the screen .
In JavaScript, the window object is the global scope object. This means that variables, properties, and methods by default belong to the window object.
the use of Window keyword is optional you can directly use alert keyword and it will work without throwing error.
Example of Console.log() :
For debugging purposes, you can call the console.log()
method in the browser to display data.
console.log() method do not provide data on page , to view the console.log() statement you need to right click on page and click on inspect then go to console there you can see the your console.log() statement.
These are some basics of JS concepts in next blog we will discuss about data type of JS , operators in JS , conditional statements and will see how to create function .
NOTE :
If you find insights in this post and get some knowledge about JavaScript basics then share this blog post . Because we believe in "Learn together Grow together".
informative , thanks
ReplyDelete