JAVASCRIPT FRONT END PROGRAMMING: Crafting Dynamic and Interactive User Interfaces with JavaScript (2024 Guide for Beginners)
()
About this ebook
"JavaScript Front End Programming" is your indispensable guide to mastering the art of front-end development, empowering you to create dynamic and engaging user interfaces with JavaScript. Tailored for both beginners and those looking to deepen their skills, this book provides hands-on examples, essential techniques, and practical insights to el
DAISY JOHNSTON
Daisy Johnston, hailing from the tech hub of San Francisco, is a seasoned front-end developer and author specializing in crafting dynamic and interactive user interfaces with JavaScript. Her passion for simplifying complex concepts makes her a perfect guide for beginners in this evolving field.
Related to JAVASCRIPT FRONT END PROGRAMMING
Related ebooks
React The Complete Reference: React Rating: 0 out of 5 stars0 ratingsLearn React Hooks: Build and refactor modern React.js applications using Hooks Rating: 0 out of 5 stars0 ratingsReact Key Concepts: An in-depth guide to React's core features Rating: 0 out of 5 stars0 ratingsReact Deep Dive Rating: 5 out of 5 stars5/5React and React Native Rating: 4 out of 5 stars4/5Mastering Sharepoint Framework Rating: 0 out of 5 stars0 ratingsGetting Started with React Rating: 0 out of 5 stars0 ratingsReact JS and Express Framework: A Comprehensive Guide Rating: 0 out of 5 stars0 ratingsReact Essentials : Building Modern Web Interfaces Rating: 0 out of 5 stars0 ratingsReact and React Native: Build cross-platform JavaScript and TypeScript apps for the web, desktop, and mobile Rating: 0 out of 5 stars0 ratingsReactJS by Example - Building Modern Web Applications with React Rating: 4 out of 5 stars4/5React Components Rating: 0 out of 5 stars0 ratingsIntroduction to Mastering Modern Web Technologies with React.js and Ant Design Rating: 0 out of 5 stars0 ratingsBuilding large scale web apps Rating: 0 out of 5 stars0 ratingsReact Native By Example Rating: 0 out of 5 stars0 ratingsMastering React Test-Driven Development: Build rock-solid, well-tested web apps with React, Redux and GraphQL Rating: 0 out of 5 stars0 ratingsJavaScript Bootcamp: Hands-On Learning For Web Developers Rating: 0 out of 5 stars0 ratingsAdvanced React Patterns Rating: 0 out of 5 stars0 ratingsAdvanced Web Development with React: SSR and PWA with Next.js using React with advanced concepts Rating: 0 out of 5 stars0 ratingsMastering JavaScript: The Complete Guide to JavaScript Mastery Rating: 5 out of 5 stars5/5React Anti-Patterns: Build efficient and maintainable React applications with test-driven development and refactoring Rating: 0 out of 5 stars0 ratingsReact.js Essentials Rating: 4 out of 5 stars4/5React Projects: Build 12 real-world applications from scratch using React, React Native, and React 360 Rating: 0 out of 5 stars0 ratingsJavascript Concepts: 1St Edition Rating: 0 out of 5 stars0 ratings
Programming For You
Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsPython: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Hacking Electronics: Learning Electronics with Arduino and Raspberry Pi, Second Edition Rating: 0 out of 5 stars0 ratingsSQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5A Slackers Guide to Coding with Python: Ultimate Beginners Guide to Learning Python Quick Rating: 0 out of 5 stars0 ratingsBuilding Business Websites with Squarespace 7 Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5OneNote: The Ultimate Guide on How to Use Microsoft OneNote for Getting Things Done Rating: 1 out of 5 stars1/5Beginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5
Reviews for JAVASCRIPT FRONT END PROGRAMMING
0 ratings0 reviews
Book preview
JAVASCRIPT FRONT END PROGRAMMING - DAISY JOHNSTON
Introduction
Developed by Facebook and released in 2013, React is one of the best front-end libraries, used to handle view layers in mobile and web apps. React JS gives us the ability to create user-interface components that we can reuse, and it is currently enjoying being the most popular community-back JavaScript library.
Who This Book is For
This guide is aimed at those who already have some developing and programming experience and want to get to grips with React JS. Throughout the book, we try to explain each concept using simple examples that you can practice for yourself. Once you have reached the end of the book, you will have the confidence to work with the library to build your own web apps and web pages.
Prerequisites
Working with React JS requires that you have a good working knowledge of JavaScript, CSS, and HTML5. And, although HTML is not used with React JS, the JSX is much like it, so a working knowledge of HTML is also useful.
The official documentation states that the React JS library helps us build composable user interfaces and strongly encourages reusable components, presenting data that will change. It provides us with a much better programming model and can use Node to render on the server.
Using React helps you implement reactive data flow, which is much easier to reason than the traditional data binding method.
React Features
React offers plenty of features:
JSX - a JavaScript syntax extension recommended for React development, although it isn’t strictly necessary. Components – React JS is strongly focused on components. Indeed, everything is a component, and if you can get into that way of thinking, you will find code maintenance much easier with large-scale projects.
Flux and Unidirectional Data Flow – One of the easiest ways to reason about your app is with the one-way data flow implemented by React, using a pattern called Flux.
React Advantages
It uses a JavaScript object called Virtual DOM, much faster than the regular DOM, and helps to improve the performance of your apps.
It can be used on both the server and client-side, as well as other frameworks
The data and component patterns make readability much better, helping to maintain much bigger apps.
React Limitations
It only works on the app view layer, so you will still need other technologies to build a complete development tool kit.
It uses JSX and inline templating, which some developers find a little awkward.
React JS is one of the best tools to have in your front-end development tool kit, so get stuck in and get to grips with all the concepts and learn how to use them through simple, practical examples.
Chapter 1 : ReactJS - Environment Setup
To kickstart your journey, we’ll begin by setting up the environment you need for success in your React development. There are quite a few steps to this, and the first one requires that you install Node.js, so that’s where we begin.
Local Environment Setup
You are going to need two things on your computer to do this – a text editor and the Installables for Node.js.
Text Editor
This is used for typing your programs, and there are several different ones you can use, such as Windows Notepad, Brief, EMACS, Vi, Vim, OS edit Command, and many more. The one you use will depend on your operating system, for example, if you use Windows, you will likely use Notepad or Vi or Vim, while Linux users would stick with Vi or Vim. When you create a file using the editor, it is known as a source file and is where your program code is stored.
Node.js source files typically have the .js extension. Before you start programming, ensure you have a text editor in place first. Make your choice and follow the download instructions on the editor’s website if you need to install one. Also, be sure you have sufficient programming experience – this book is not for those who have no experience.
Node.js Runtime
When you write your source code in the source file, it is written in JavaScript, and the Node.js interpreter reads, interprets, and executes the code. Node.js is a binary installation for Linux, SunOS, macOS, and Windows, both 32-bit and 64-bit architectures.
Download Node.js Archive
Download the newest version of the file from http://nodejs.org/download/ for your specific operating system. macOS/Linux/Unix/SunOS Download the file and open it on your computer. Extract the archive node file called (osname).tar.gz into /tmp. Move the files from there to a directory named /usr/local/nodejs. Here’s an example:
$ cd /tmp
$ wget http://nodejs.org/dist/v6.3.1/node-v6.3.1-linux-x64.tar.gz
$ tar xvfz node-v6.3.1-linux-x64.tar.gz
$ mkdir -p /usr/local/nodejs
$ mv node-v6.3.1-linux-x64/* /usr/local/nodejs
Now add /usr/local/nodejs/bin to your PATH environment variable using
one of the commands below, depending on your OS:
Linux - export PATH=$PATH:/usr/local/nodejs/bin
Mac - export PATH=$PATH:/usr/local/nodejs/bin
FreeBSD - export PATH=$PATH:/usr/local/nodejs/bin
Windows
Download the MSI file and follow the on-screen prompts to get Node.js on your system. The installer should use the default option of C:\Program Files\node.js to install the file and set the bin directory (C:\Program Files\nodejs\bin) in the Path environment variable for you. If you have open command prompts, restart them so the changes can take effect.
Verifying the Installation
Create a new file and name it main.js. Then add the code below to it:
/* Hello, World! program in node.js */
console.log(Hello, World!
)
Use the Node.js interpreter to execute the file using this command:
$ node main.js
You should see the following on your screen:
Hello, World!
Once Node.js is installed and working, React can be installed on it using
npm. There are two ways to do this:
With Webpack and Babel
With the create-react-app command
With Webpack and Babel
Webpack manages independent modules and loads them and is commonly known as a module bundler. It compiles dependent modules into one bundle, a singles file, and this can be used during your app development in two ways – call it using the command line or use webpack.config to configure it. Babel compiles and transpiles JavaScript and is used for converting a source code into another one.
This allows you to use the EC6 code features because Babel will convert it to EC5, which any browser can use.
Step One – Creating the Root Folder
Create a new folder and call it reactApp. This is where all the required files will be installed with the mkdir command: C:\Users\username\Desktop>mkdir reactApp C:\Users\username\Desktop>cd reactApp Creating a module requires that the package.json file is generated so, once your folder is created, create another file called package.json.
To do this, run the following npm init command at the command prompt: C:\Users\username\Desktop\reactApp>npm init That command is asking for module information, like author, description, package name and so on. You can avoid all this by using the -y option, like this.
C:\Users\username\Desktop\reactApp>npm init -y
Written to C:\reactApp\package.json:
{
name
: reactApp
,
version
: 1.0.0
,
description
: ,
main
: index.js
,
scripts
: {
test
: echo \"Error: no test specified\" && exit 1
},
keywords
: [],
author
: ,
license
: "ISC
Step Two – Installing React and react dom
We are trying to install ReactJS along with all its dom packages, and we do
that with two npm commands – install react and react-dom. Use the –save
option to add these packages to the package.json file:
C:\Users\Username\Desktop\reactApp>npm install react —save
C:\Users\Username\Desktop\reactApp>npm install react-dom —save
Alternatively, use one single command to install and save everything:
C:\Users\username\Desktop\reactApp>npm install react react-dom –save
Step Three – Installing Webpack
Because webpack is being used to generate the bundler, we need to install
here things – webpack, webpack-dev-server, and webpack-cli:
C:\Users\username\Desktop\reactApp>npm install webpack —save
C:\Users\username\Desktop\reactApp>npm install webpack-dev-server —save
C:\Users\username\Desktop\reactApp>npm install webpack-cli —save
Or use one command to install everything:
C:\Users\username\Desktop\reactApp>npm install webpack webpack-dev-server webpackcli —save
Step Four – Installing Babel
Now we want babel installed, along with the relevant plugins:
C:\Users\username\Desktop\reactApp>npm install babel-core —save-dev
C:\Users\username\Desktop\reactApp>npm install babel-loader —save-dev
C:\Users\username\Desktop\reactApp>npm install babel-preset-env —save-dev
C:\Users\username\Desktop\reactApp>npm install babel-preset-react —save-dev
C:\Users\username\Desktop\reactApp>npm install html-webpack-plugin —save-dev
Or use one command to install them all:
C:\Users\username\Desktop\reactApp>npm install babel-core babel-loader babel-presetenv babel-preset-react html-webpack-plugin —save-dev
Step Five – Creating the Files
To finish, more files need to be created and these can be created manually
or by using the command prompt. These are the required files:
C:\Users\username\Desktop\reactApp>type nul > index.html
C:\Users\username\Desktop\reactApp>type nul > App.js
C:\Users\username\Desktop\reactApp>type nul > main.js
C:\Users\username\Desktop\reactApp>type nul > webpack.config.js
C:\Users\username\Desktop\reactApp>type nul > .babelrc
Step Six – Setting the Compiler, Server, and Loaders
Open the file called webpack-config.js and add in the code below. What this
does is set main.js as the webpack entry point. The output path is where the
bundled app is served, and the development server is also being set as 8001
port, although you can choose whatever port you want.
webpack.config.js
const path = require(‘path’);
const HtmlWebpackPlugin = require(‘html-webpack-plugin’);
module.exports = {
entry: ‘./main.js’,
output: {
path: path.join(__dirname, ‘/bundle’),
filename: ‘index_bundle.js’
},
devServer: {
inline: true,
port: 8001
},
module: {
rules: [ ]
test: /\.jsx?$/,
exclude: /node_modules/,
loader: ‘babel-loader’,
query: {
presets: [‘es2015’, ‘react’]
plugins:[
new HtmlWebpackPlugin({
template: ‘./index.html’
})
Open package.json and delete the following from the Scripts object:
test
echo
\ Error: no test specified\" && exit 1
We delete this because we don’t intend to test anything right now.
Instead, we can add two more commands – start and build:
start
: "webpack-dev-server —mode development